开发者

$.ajax send POST and receive JSON

I want to send a POST request to a PHP script which then will return a JSON string.

I开发者_运维技巧 am wondering if this is possible using $.ajax method?


You can try this:

$.ajax({
   type: "POST",
   url: "some.php",
   data: "name=John&location=Boston",
   success: function(msg){
     alert( "Data Saved: " + msg );
   }
 });

And in PHP you can do this

<?php
$return = $_POST;
echo json_encode($return);


Yes, you can return any data you like. Just make sure that you output the correct Content-Type header.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜