1

我有以下内容:

在客户端,我有以下内容:

for (var i = 0; i < myArray1.length; i++) 
{
  var dat = encodeURIComponent(document.getElementById(myArray1[i]).value);
  var obj = {
             id:myArray1[i],
             val:dat
            };
  jsonObj.push(obj);

}

$.ajax({
        type: "POST",
        url: "example/example.php?id="+id+"&ps="+ps+"&json="+JSON.stringify(jsonObj),
        success: function(data){
        alert('Request Complete');
        failure: function(errMsg) {
        alert('Your Request Could Not Be Completed - error:3');
        }
      });

这有效,在 PHP 脚本(example.php)上我有以下内容:

    $url = "http://TheOtherServer/example2.php?
            func=12&id=".$_GET['id']."&ps=".$_GET['ps'];

    $content = $_GET['json'];
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER,
            array("Content-type: application/json"));
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $content);

    $json_response = curl_exec($curl);

    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

    curl_close($curl);

    $response = json_decode($json_response, true);
    if ( $status == 200 && $response == '01') {
        echo '01';
    }
    else
    {
        echo $response;
    }

如果我错误记录 $_GET json 它是正确的,那么这些似乎是有序的。在另一台服务器(example2.php)我有

 $json = (json_decode(file_get_contents("php://input")));

这将返回一个空值。谁能看到我哪里出错了?

4

0 回答 0