Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用json的AJAX Post调用_Php_Ajax_Json - Fatal编程技术网

Php 使用json的AJAX Post调用

Php 使用json的AJAX Post调用,php,ajax,json,Php,Ajax,Json,我需要一些关于JSON对象和使用它的Ajax调用的帮助。出于某种目的,我需要传递此数据以更新我的数据库: JSON字符串: [{"id":"1"},{"id":"10"},{"id":"2"},{"id":"3"},{"id":"4"},{"id":"5"},{"id":"6"},{"id":"7"},{"id":"8"},{"id":"9"}] 我正在使用ajaxpost。我的代码: $.ajax({ url: "hello_world.php", type: "POST",

我需要一些关于JSON对象和使用它的Ajax调用的帮助。出于某种目的,我需要传递此数据以更新我的数据库:

JSON字符串:

[{"id":"1"},{"id":"10"},{"id":"2"},{"id":"3"},{"id":"4"},{"id":"5"},{"id":"6"},{"id":"7"},{"id":"8"},{"id":"9"}]
我正在使用ajaxpost。我的代码:

$.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 + "\n" +
            "Message: " + xhr.statusText + "\n" +
            "Response: " + xhr.responseText + "\n" + thrownError);
    }
});
PHP代码:

<?php

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

?>


data:{data:jsonString}
可能有助于在php端处理数据时发送包含关键数据的对象。在发送ajax之前,请先对数据进行字符串化
$json = file_get_contents('php://input');
$decoded = json_decode($json, TRUE);
var_export($decoded); # for testing else use echo json_encode($decoded);