开发者

$.ajax send POST and receive JSON

开发者 https://www.devze.com 2023-04-12 06:38 出处:网络
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:

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

精彩评论

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