php - jQuery AJAX JSON data not sending -


i have below code running send data json object

var jdata = json.stringify(grid.serialize()); $.ajax({     'type': 'post',     'url': 'print.php',     'data': jdata, //assuming have json library linked.     'contenttype': "application/json",     'success': function (data) {         alert(data);     },     'error': function (x, y, z) {         alert(x.responsetext);         // x.responsetext should have what's wrong     } }); alert(json.stringify(grid.serialize())); 

currenty alert after ajax function prints

[{"id":"1","col":"1","row":"1","size_y":"1","size_x":"1"},{"id":"2","col":"2","row":"1","size_y":"1","size_x":"1"}]

on receiving page using <?php print_r($_post) ?> see page being sent , keeps outputting

array ( ) 

i must missing simple have been unable figure out what. maybe fresh set of eyes see simple mistake have made.

i think $_post populated if send data encoded x-www-form-urlencoded. so, assign json string key (jquery takes care of encoding properly):

'data': {data: jdata} 

and remove 'contenttype': "application/json" part.

then data in php with:

$data = json_decode($_post['data'], true); 

alternatively, raw body of request in php , process it: how retrieve request payload


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -