douzhan8395 2016-08-25 13:51
浏览 21
已采纳

无法在php文件中找到数据,由ajax发送

I create to file ajax.php and jajaxget.php.

script in ajax.php is-

<script>
var data={name:"nikhil"};
$.ajax({type:"post",url:"jajaxget.php",data: {name:"nikhil"},success:function(r,s){alert(s);alert(r);}});
</script> 

and jajaxget.php is

<!doctype html>
<html>
<body>
<?php
echo $_POST["name"];
?>

ajax.php works fine and in alert i can see the data which i send. I get a success alert and this ALERT

alert

But when i open the get.php file in browser there is nothing . "nikhil" should show on the page. but the page is blank . why data is not recived by jajaxget.php file. It may be very foolish question .but please help

  • 写回答

1条回答 默认 最新

  • dthl8036 2016-08-25 13:55
    关注

    That should not show on the page when you open it on the browser because you are not passing any POST data when you do so. Your code is working as expected. I think your problem is you do not really get to understand how GET/POST works.

    In the post environment variable the post data sent on request is stored. It is not stored forever nor as kind of a cookie. When you make another request, the variable will have different data according with the headers of the request.

    So when you are using AJAX and send post data to your file, the return shows the "name" value you've passed because you've sent it on the request headers. However, when you request the page on a browser and you are not passing any POST data, that won't be shown, because nothing you've sent.

    If you want your server to store that data, you may use databases or cookies for that.

    For more information read some webpages online like http://www.w3schools.com/tags/ref_httpmethods.asp. And please try to understand a bit how the web works before filing it of low quality questions.

    If you still have doubts, please ask me.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决
  • ¥15 请问维特智能的安卓APP在手机上存储传感器数据后,如何找到它的存储路径?