bauhsoj
08-21-2005, 01:07 AM
When I send via GET using XMLHttpRequest to a PHP script then the data is received, but if I do the same with POST then nothing makes it through.
Here's my simple JavaScript function (tested in Firefox only) which works with GET but apparently won't send POST data:function requestXML(url, post) {
xml_request = false;
if (window.XMLHttpRequest) {
try {
xml_request = new XMLHttpRequest();
} catch(e) {
xml_request = false;
}
}
if (xml_request) {
xml_request.onreadystatechange = processChange;
// Check for POST values.
if (post) {
xml_request.open("POST", url, true);
xml_request.send(post);
} else {
xml_request.open("GET", url, true);
xml_request.send("");
}
}
}
It is called like-so with POST:onClick="requestXML('http://localhost/update.php', this.name + '=' + this.value)"
It is called like-so with GET:onClick="requestXML('http://localhost/update.php?' + this.name + '=' + this.value)"
The PHP script that responds simply executes print_r($_REQUEST); and the JavaScript function processChange simply displays the output (or an error) in an alert box.
If I send via GET, then the alert box displays the values sent. With POST, the alert box is empty.
Any ideas what might be gumming up the works?
Here's my simple JavaScript function (tested in Firefox only) which works with GET but apparently won't send POST data:function requestXML(url, post) {
xml_request = false;
if (window.XMLHttpRequest) {
try {
xml_request = new XMLHttpRequest();
} catch(e) {
xml_request = false;
}
}
if (xml_request) {
xml_request.onreadystatechange = processChange;
// Check for POST values.
if (post) {
xml_request.open("POST", url, true);
xml_request.send(post);
} else {
xml_request.open("GET", url, true);
xml_request.send("");
}
}
}
It is called like-so with POST:onClick="requestXML('http://localhost/update.php', this.name + '=' + this.value)"
It is called like-so with GET:onClick="requestXML('http://localhost/update.php?' + this.name + '=' + this.value)"
The PHP script that responds simply executes print_r($_REQUEST); and the JavaScript function processChange simply displays the output (or an error) in an alert box.
If I send via GET, then the alert box displays the values sent. With POST, the alert box is empty.
Any ideas what might be gumming up the works?