<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<script>
$.ajax({
type: 'POST',
url: "http://localhost/bubblewitch/index.php/rpc/ClientApi",
data: JSON.stringify("[{2:2},{1:1}]"),
success: function(){},
dataType: "text",
contentType: "application/json-rpc",
timeout:60000,
error: function(){}
}); 
</script>
以上是我的代码,我用POST过来传到服务器,结果我在服务器 $_POST里获取不到
这是为什么??,是不是 application/json-rpc的传输格式导致的,如果这 application/json-rpc传输格式我要怎么在后端获取POST值

解决方案 »

  1.   

    我记得post传值需要设定 Content-Type: application/x-www-form-urlencoded 报头,而你的contentType: "application/json-rpc" 覆盖了它。因此服务器不能识别。
    对php来说,JSON也就是一个普通字符串而已,没必要去声明那种类型
      

  2.   

    $s = fopen("php://input", 'rb');
    echo fread($s, 10000);
      

  3.   

    当然有:$s = file_get_contents('php://input');$s 就是传入的参数
      

  4.   

    想问下为什么没有在 $_POST里,数据是POST过来,为什么接收不到????
      

  5.   

    $.ajax({
      type: "POST",
      url: "some.php",
      data: "name=John&location=Boston"
    }).done(function( msg ) {
      alert( "Data Saved: " + msg );
    });
      

  6.   

    $s = file_get_contents('php://input');
    太厉害了
    学习了
    牛人啊