Forum Moderators: open

Message Too Old, No Replies

ajax POST why wont it work for me?

ajax post

         

ulrisa

6:40 pm on Jul 17, 2008 (gmt 0)

10+ Year Member



Hi i am trying to change a ajax function the dochange function works fine but i want another one who sends the user to another page ive called it postchange here. I cant figure out why it doesent work ill appriciate all help i can get here...

//HERES THE ORIGINAL WORKS FINE
function dochange(src, val) {
var req = Inint_AJAX();
req.onreadystatechange = function () {
if (req.readyState==4) {
if (req.status==200) {
document.getElementById(src).innerHTML=req.responseText; //retuen value
}
}
};
req.open("GET", "state.php?data="+src+"&val="+val); //make connection
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
req.send(null); //send value
}

//THIS ONE IS MY CREATION DOES NOT WORK AT ALL ...
function posthange(val) {
var req = Inint_AJAX();
req.onreadystatechange = function () {
if (req.readyState==4) {
if (req.status==200) {
document.getElementById(src).innerHTML=req.responseText; //retuen value
}
}
};
req.open("POST", "../BokaTid.php?val="+val); //make connection
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
req.send(null); //send value
}

DrDoc

5:23 pm on Jul 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are using POST, you need to actually POST the data, not send it in the query string.

Take a look at the

req.open
line. If you use GET, the arguments should be supplied as key value pairs the way they are in a regular query string. If the method is POST, however, you need to send the data using the
req.send
function call.