Object properties are lost on the $ .ajax POST request

I load a large dataset as JSON via $ .ajax, and some properties are lost during this download. For testing purposes, the server returns the first row where the property is missing.

Javascript

function parseResults(data) {
    var send = [];
    for (var x in data) {
        var row = data[x],
            code = row["ORDER"];
        if (typeof code === "undefined") continue;
        if (code == "") continue;
        var temp = {
            code: code,
            date: row["CREATED DATE"] + " " + row["CREATED TIME"],
            pt: row["PAYMENT_CODE"],
            loc: row["LOCATION"],
            fv: row["ORDER VOLUME"],
            fpdf: row["DELIVERY FEE"],
            fpsf: row["SERVICE FEE"],
            vsf: row["REST. SERVICE FEE"],
            pr: row["PAY RESTAURANT"],
            to: row["TOTAL ORDER"],
            delc: row["ORDER PROVIDER"],
            city: row["City"],
            vp: row["VENDOR PROVIDER"],
            rest: row["VENDOR"],
            vouch: row["VOUCHER AMOUNT"],
            cust: row["CUST CODE"],
            st: row["STATUS"]
        };
        send.push(temp);
    }
    sendResults(send);
}

function sendResults(data) {
    for (var x in data) {
        if (data[x].code == "m0sq-p0yq") {
            // this one is here just for testing
            // purposes, you will see
            console.log(data[x]);
        }
    }
    $.ajax({
        type: "POST",
        url: "/ordersfp/process",
        data: {
            data: data
        },
        success: function(response) {
            console.log(response);
        }
    }, "json");
}

Php

public function handleProcess()
{
    $data = Input::all();
    foreach ($data['data'] as $row) {
        if (!isset($row['cust'])) {
            return $row;
        }
        // ...
    }
}

So, everything works as it should, the only problem is that this particular element with the code "m0sq-p0yq"somewhere loses the property cust.

Console Log of this object

In addition, I just noticed that the property is stalso lost. - Please help :)

+4
source share
1 answer

ajax JSON, application/x-www-form-urlencoded. "json" $.ajax .

jQuery $.ajax :

  • URL, -
  • ,

ajax :

$.ajax({
    type: "POST",
    url: "/ordersfp/process",
    data: {
        data: JSON.stringify(data) // encode to JSON
    },
    success: function(response) {
        console.log(response);
    }
});

PHP JSON:

$data = Input::all();
$decoded = json_decode($data['data']);
foreach ($decoded as $row) {
+2

All Articles