$.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.
精彩评论