Friday, 15 January 2010

ajax - handle json request in PHP -



ajax - handle json request in PHP -

when making ajax call, when contenttype set application/json instead of default x-www-form-urlencoded, server side (in php) can't post parameters. in next working example, if set contenttype "application/json" in ajax request, php $_post empty. why happen? how can handle request contenttype application/json in php?

$.ajax({ cache: false, type: "post", url: "xxx.php", //contenttype: "application/json", processdata: true, data: {my_params:123}, success: function(res){ }, complete: function(xmlhttprequest, text_status) { } });

<?php var_dump(json_decode(file_get_contents('php://input'))); ?>

php ajax json request mime-types

No comments:

Post a Comment