开发者

How to collect jquery.ajax() data in PHP?

I send data from 开发者_如何转开发javascript to PHP like this:

$.ajax({'url': 'my.php',
        'type': 'POST',
        'data': JSON.stringify(update_data),
        'success': function(response) {
                       alert(response);
                   }
       });

Using HTTPFOX Firefox plug-in I see the following data in the POST DATA tab:

{"file_id":["1","2","3"],"description":["lala","kuku","wow!"],"tags":[["julia","paper"],["Very nice car"],[]]}

however, if I do in my.php print_r($_POST) I see an empty array. Why is that ? How could I collect the data ?


The data needs to be in the form name=value.

try...

$.ajax({'url': 'my.php',
        'type': 'POST',
        'data': 'mydata=' + JSON.stringify(update_data),
        'success': function(response) {
                       alert(response);
                   }
       });

Then you should have your json string in $_POST['mydata']

You'll then need to use json_decode to actually get at the individual values in your string.

http://php.net/manual/en/function.json-decode.php


The response you are getting is in JSON format. Use the json_decode function to convert it to array.

print_r(json_decode($_POST['description'], true));


I'd expect your data to be in $HTTP_RAW_POST_DATA. Then json_decode to make sense of it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜