weixin_33693070 2014-07-08 04:28 采纳率: 0%
浏览 6

使用JSON进行AJAX发布通话

I need some help with a JSON object and the Ajax call using it. I need to pass this data to update my database for some purpose:

JSON string:

[{"id":"1"},{"id":"10"},{"id":"2"},{"id":"3"},{"id":"4"},{"id":"5"},{"id":"6"},{"id":"7"},{"id":"8"},{"id":"9"}]

I am using AJAX Post. My code:

$.ajax({
    url: "hello_world.php",
    type: "POST",
    data: JSON.stringify(jsonString),
    processData: false,
    contentType: 'application/json', 
    dataType: 'json',
    success: function(data){
        alert("Call success");
    },
    error: function (xhr, ajaxOptions, thrownError) {
        alert("Error: " + xhr.status + "
" +
            "Message: " + xhr.statusText + "
" +
            "Response: " + xhr.responseText + "
" + thrownError);
    }
});

PHP Code :

<?php

if(isset($_POST))
   {
     $json = file_get_contents('php://input');
        $decoded = json_decode($json, TRUE);
        echo $decoded;
   }

?>
  • 写回答

1条回答 默认 最新

  • Lotus@ 2014-07-08 04:33
    关注
    $json = file_get_contents('php://input');
    $decoded = json_decode($json, TRUE);
    var_export($decoded); # for testing else use echo json_encode($decoded);
    
    评论

报告相同问题?