简体   繁体   English

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

[英]PHP-AJAX; POST METHOD problem

I am using ajax, php with my application. 我在我的应用程序中使用ajax,php。 In sending the data from ajax to php, when i use the $_GET, I can have the data. 在将数据从ajax发送到php时,当我使用$ _GET时,我可以获得数据。 but when i try to use $_POST since i read it is more secure, it cannot access the data. 但是当我尝试使用$ _POST时,因为我读它比较安全,所以它无法访问数据。 When i echo the value, it's blank. 当我回显该值时,它为空。

I tried changing the register_globals = off to on in the php.ini, but still not working. 我尝试在php.ini中将register_globals = off更改为on,但是仍然无法正常工作。

did i miss out on something? 我错过了什么吗?

this is my js file: 这是我的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 file php文件

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

thanks a lot, tinks 非常感谢

I don't see you specifying a key for the data that's being POSTed, which is what your PHP script is looking for. 我看不到您为要发布的数据指定密钥,而这正是您的PHP脚本正在寻找的密钥。

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

Yeah you need to specify a key. 是的,您需要指定一个密钥。 The post method on this link might help: 此链接上的post方法可能会有所帮助:

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

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

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