0

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-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
$selectedID = $_POST['params'];
echo "hello there ". $selectedID;
?>

thanks a lot, tinks

2 Answers 2

2

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);

Sign up to request clarification or add additional context in comments.

1 Comment

i would rather try ajaxRequest.send("params=" + params);
0

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

1 Comment

hey guys!! thank you so much! yeah it needed the key.. it is working now!!! thank you! :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.