PDA

View Full Version : JSON POST Issue



rjthecarguy
24 Dec 2013, 1:26 AM
This is my Proxy:


proxy: {
type: 'ajax',
api: {
read: 'http://mysite.net/login/php/parts.php',
update: 'http://mysite.net/login/php/updatePart.php',
},

reader: {
type: 'json',
root: 'parts',
successProperty: 'success'
}
}


In updatePart.php I have this to read/decode the JSON POST:


$data = file_get_contents('php://input');
$data = json_decode($data, true);


Which gives me this when I save the first record, which is fine:


Array
(
[id] => 1
[title] => BA30 Belt Kit
[part] => BA30BK
[desc] => Ardac Upstack belt kit (4 pieces-with drive belts, not wheels
[price] => 15
[addOn1] => Shipping weight per item: .05 Lbs
[multi] => n
[weight] => .05
[tax] => y
[pic] => BA30belts.jpg
[brand] => logo-Mars.jpg
)

But when I save a second record, I get this:


Array
(
[0] => Array
(
[id] => 1
[title] => BA30 Belt Kit
[part] => BA30BK
[desc] => Ardac Upstack belt kit (4 pieces-with drive belts, not wheels
[price] => 15
[addOn1] => Shipping weight per item: .05 Lbs
[multi] => n
[weight] => .05
[tax] => y
[pic] => BA30belts.jpg
[brand] => logo-Mars.jpg
)


[1] => Array
(
[id] => 2
[title] => MAG50 Belt Kit
[part] => Mag50BK00
[desc] => Coinco Mag50 belt kit (7 pieces)
[price] => 17
[addOn1] => Shipping weight per item: .05 Lbs
[multi] => n
[weight] => .05
[tax] => y
[pic] => MAGbelts.jpg
[brand] => logo-Coinco.jpg
)


)

Both records are in the "request payload" section of the header and are getting sent to the server. Why both records? I would think each ajax submission would be a single record.

Thanks for the help!

RJ

scottmartin
24 Dec 2013, 2:34 PM
Where is the data coming from? A form .. or?

rjthecarguy
24 Dec 2013, 3:02 PM
It's coming from a grid. It is basically the MVC example except the proxy is AJAX instead of a file.