I am using ajax, php with my application. In sending the data from ajax to php, when i use the $_GET, I can have the data. but when i try to use $_POST since i read it is more secure, it cannot access the data. 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.
did i miss out on something?
this is my js file:
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-for开发者_C百科m-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
$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.
Try changing ajaxRequest.send(params);
to ajaxRequest.send("params=" + params);
Yeah you need to specify a key. The post method on this link might help:
http://www.openjs.com/articles/ajax_xmlhttp_using_post.php
精彩评论