Skip to content
Advertisement

AJAX Post is sending only partial rows PHP

AJAX Post is sending only partial rows PHP. This is my code:

$.ajax({
    type: "POST",
    url: "code.php",
    data: {"excelRows":excelRows},
    dataType: "json",
    success: function(data) {
        alert(data.d);
    },
    error: function(data){
        alert("fail");
    }
});
    }

excelRows contains 39 rows, but I am getting only 25 rows to PHP. Here is my PHP script –

$answer = $_POST ['excelRows'];

Advertisement

Answer

UPDATE

Here is a sample AJAX-call with the data you provided. So far everything works OK. Maybe you should try it out again with your original data and closely watch where it stops working. This might give you a clue as to what needs fixing …

In the following sample code I sent the data in a “multiplied form” (ending up as an array with 48 elements). If I double it again it would lead to a failed AJAX call. This might be caused by the receiving end accepting only input up to a certain length. Needs to be further investigated (no time at the moment).

const excelrows={
    "Sheet1": [
        {
            "Policy Number": "4106/151212/00/000",
            "Name Of The Insured": "RAM",
            "Name Of The Self Member": "KADAMBINI",
            "Relationship": "WIFE",
            "Card Number/UHID": "IL1666",
            "Member Reference No.": "444",
            "Sum Assured": "5455",
            "Category Of Claim": "REIMBURSEMENT",
            "Claim-Hospital Name": "OMNI Hospitals",
            "Type Of Claim": "FRESH CLAIM",
            "Claim-Inward Number": "CL-0123",
            "Claim-Inward Date": "29 Sep 18",
            "Claim Number": "278656",
            "undefined": "Other",
            "Claim-Final Diagnosis": "Myeloid leukaemia~Other septicaemia",
            "Claim-Documents Received Date": "28 Sep 18",
            "Claim-Date Of Admission": "2 Aug 18",
            "Claim-Date Of Discharge": "17 Aug 18",
            "Claim-Status": "APPROVED AND PAID",
            "Claim-Date Of Approval": "11/5/2018",
            "Days": "38",
            "Claim-Amount Claimed": "187765",
            "Claim-Sanctioned Amount": "420",
            "Claim-Disallowed Amount": "~~~gate pass~diapers",
            "Claim-Co-Payment Deduction": "FT",
            "Payment Mode": "5 Nov 18",
            "Claim-Cheque Date": "UYYY",
            "Claim-Cheque Number": "0",
            "Service Tax Rate": "888888",
            "TDS Rate": "0",
            "Claim-Service Tax Amt": "193399",
            "Batch-Service Tax Amt": "15 Oct 18",
            "Batch-TDS Amt": "23 Oct 18",
            "Claim-Date Of Query Revert": "N"
        },
        {
            "Policy Number": "4106/151212/00/000",
            "Name Of The Insured": "SUCHITA",
            "Name Of The Self Member": "SELF",
            "Relationship": "IL1640",
            "Card Number/UHID": "1342",
            "Member Reference No.": "333333",
            "Sum Assured": "REIMBURSEMENT",
            "AL-Copay Deduction": "Maxcure",
            "Claim-Hospital Name": "FRESH CLAIM",
            "Type Of Claim": "CL-09989",
            "Claim-Inward Number": "21 Nov 18",
            "Claim-Inward Date": "27865566",
            "Claim Number": "Other",
            "undefined": "Dengue fever",
            "Claim-Final Diagnosis": "20 Nov 18",
            "Claim-Documents Received Date": "12 Oct 18",
            "Claim-Date Of Admission": "14 Oct 18",
            "Claim-Date Of Discharge": "APPROVED AND PAID",
            "Claim-Status": "12/11/2018",
            "Claim-Date Of Approval": "21",
            "Days": "187755",
            "Claim-Amount Claimed": "109876",
            "Claim-Sanctioned Amount": "62577",
            "Claim-Disallowed Amount": "NA",
            "Claim-Co-Payment Deduction": "FT",
            "Payment Mode": "11 Dec 18",
            "Claim-Cheque Date": "JUYGH98",
            "Claim-Cheque Number": "0",
            "Service Tax Rate": "181988",
            "TDS Rate": "0",
            "Claim-Service Tax Amt": "109961",
            "Claim-Date Of Last Query Sent": "IYT/9087",
            "Claim-Date Of Query Revert": "N"
        },
        {
            "Policy Number": "4106/151212/00/000",
            "Name Of The Insured": "NAGI REDDY",
            "Name Of The Self Member": "SELF",
            "Relationship": "IL1656",
            "Card Number/UHID": "113",
            "Member Reference No.": "34210",
            "Sum Assured": "CASHLESS",
            "Category Of Claim": "AL-5546",
            "AL-Inward Number": "3 Sep 18",
            "AL-Inward Date": "1108796",
            "AL-Number": "3 Sep 18",
            "AL-Expected Date Of Admission": "Other specified fever",
            "AL-Diagnosis": "APPROVED",
            "AL-Status": "59708",
            "AL-Sanction Date": "3 Sep 18",
            "AL-Copay Deduction": "Nizams Institute",
            "Claim-Hospital Name": "FRESH CLAIM",
            "Type Of Claim": "CL-0879",
            "Claim-Inward Number": "13 Oct 18",
            "Claim-Inward Date": "2012324",
            "Claim Number": "Infectious Diseases",
            "undefined": "O VARIAN CYSTECTOMY",
            "Claim-Final Diagnosis": "12 Oct 18",
            "Claim-Documents Received Date": "3 Sep 18",
            "Claim-Date Of Admission": "7 Sep 18",
            "Claim-Date Of Discharge": "APPROVED AND PAID",
            "Claim-Status": "12/14/2018",
            "Claim-Date Of Approval": "63",
            "Days": "77777",
            "Claim-Amount Claimed": "57002",
            "Claim-Sanctioned Amount": "3856",
            "Claim-Disallowed Amount": "NA",
            "Claim-Co-Payment Deduction": "FT",
            "Payment Mode": "14 Dec 18",
            "Claim-Cheque Date": "HUYU7677",
            "Claim-Cheque Number": "10.3",
            "Service Tax Rate": "10",
            "TDS Rate": "0",
            "Claim-Service Tax Amt": "5701",
            "Claim-TDS Amt": "87666",
            "Claim-Transferred Amt": "0",
            "Batch-Service Tax Amt": "5701",
            "Batch-TDS Amt": "51301",
            "DISEASE CODE": "IYT/9087",
            "NT CODE": "N"
        }
    ]
};
for (let i=4; i--;) excelrows.Sheet1=excelrows.Sheet1.concat(...excelrows.Sheet1)
// const excelrows=[...Array(1000)].map((_,i)=>["Row_"+i,i,i*i,i*i*i]);
$.ajax({
  type: "POST",
  url: "https://jsonplaceholder.typicode.com/users",
  data: { "excelRows": JSON.stringify(excelrows).replaceAll("],","],n") },
  dataType: "JSON",
  success: function (data) {
    console.log(JSON.parse(data.excelRows).Sheet1.length);
  },
  error: function (data) {
    alert("fail");
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

However, if you want so sent two-dimensional data it is recommended that you JSON encode them first.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement