douduikai0562
2014-06-02 00:31
浏览 40
已采纳

Ajax / Jquery与PHP通信

I am completely new to Ajax (Jquery POST), and I wrote this thing to try to "talk" to a .php file:

function send(d){
    $.post("http://somesite.net/read.php",{data:d})
    .done(function(data){
        document.getElementById('res').innerHTML=data;
    });
}

Read.php:

$d=$_POST["d"];
echo $d;

So, it does return stuff, but it seems like it returns the entire file. It is very likely I am doing something incredibly wrong. I would like to know what it is.

图片转代码服务由CSDN问答提供 功能建议

我是Ajax(Jquery POST)的新手,我写了这个东西试图“谈”到一个 .php文件:

  function send(d){
 $ .post(“http://somesite.net/read.php”,{data:d})  
 .done(function(data){
 document.getElementById('res')。innerHTML = data; 
}); 
} 
   
 
 

Read.php:

  $ d = $ _ POST [“d”]; 
e $ d; 
   
 
 

因此,它确实会返回内容,但它似乎会返回整个文件。 我很可能做了一件令人难以置信的错事。 我想知道它是什么。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doucan2102 2014-06-02 00:39
    已采纳

    It should be:

    $d=$_POST["data"];
    echo $d;
    

    See this line:

    {data:d}
    

    You are sending variable data with a value d. So in your backend, you should request for variable name.

    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题