繁体   English   中英

PHP-AJAX; 开机自检方法问题

[英]PHP-AJAX; POST METHOD problem

我在我的应用程序中使用ajax,php。 在将数据从ajax发送到php时,当我使用$ _GET时,我可以获得数据。 但是当我尝试使用$ _POST时,因为我读它比较安全,所以它无法访问数据。 当我回显该值时,它为空。

我尝试在php.ini中将register_globals = off更改为on,但是仍然无法正常工作。

我错过了什么吗?

这是我的js文件:

var params=arguments[0].options[arguments[0].selectedIndex].value;
 var url = "http://localhost/myprocess.php";
 ajaxRequest.open("POST",url, true);

 ajaxRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
 ajaxRequest.setRequestHeader("Content-length",params.length);
 ajaxRequest.setRequestHeader("Connection", "close");

 ajaxRequest.onreadystatechange = function(){
     if ((ajaxRequest.readyState == 4) && (ajaxRequest.status == 200)) 
    {
    //Get data from server's response
    alert("response text is:");
    alert(ajaxRequest.responseText);   -->does not show anything; blank
   }
  }
 ajaxRequest.send(params);
}

php文件

<?php
$selectedID = $_POST['params'];
echo "hello there ". $selectedID;
?>

非常感谢

我看不到您为要发布的数据指定密钥,而这正是您的PHP脚本正在寻找的密钥。

尝试更改ajaxRequest.send(params); ajaxRequest.send("params=" + params);

是的,您需要指定一个密钥。 此链接上的post方法可能会有所帮助:

http://www.openjs.com/articles/ajax_xmlhttp_using_post.php

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM