Cannot send message using POST
The ajax code:
Code:
var xmlHttp = GetXmlHttpObject();
if (xmlHttp == null) {
window.alert("Your browser does not support ajax.\n Please use latest version of your browser.");
return;
}
if (xmlHttp.overrideMimeType)
xmlHttp.overrideMimeType("text/xml");
xmlHttp.open("POST", "signup_server.php", true);
xmlHttp.setRequestHeader("Content-Type",
"application/x-www-form- urlencoded; charset=UTF-8");
var str = "name=n";
xmlHttp.send(str);
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
window.status = xmlHttp.responseText;
}
else
window.alert("Error " + xmlHttp.status + ": " + xmlHttp.statusText);
}
}
Server side code:
Code:
<?php
if (isset($_POST["name"]))
echo $_POST["name"];
else
echo "Name not found.";
?>
After execution, the window.status contains "Name not found." string. Why the server cannot get the name=n? I'm using IIS in Windows XP SP2 and PHP version 5.2.5.
Thanks in advance.
Re: Cannot send message using POST
Maybe it is because of the space before urlencoded in:
Code:
"application/x-www-form- urlencoded; charset=UTF-8");
Here is what I use:
Code:
obj.open('POST', url, true);
obj.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
obj.setRequestHeader('Content-length', parameters.length);
obj.setRequestHeader('Connection', 'close');
obj.send(parameters);
obj.onreadystatechange = function() {
if (obj.readyState == 4) {
if (obj.status == 200) {
func(obj.responseText);
}
}
Or maybe you should close the connection for the header.
Re: Cannot send message using POST
I think the URL called has to be absolute, doesn't it? Also I haven't figured out why, but I had to assign my url to a var first before calling a Perl script. Don't know if this applies to PHP.
Try changing xmlHttp.open("POST", "signup_server.php", true); to xmlHttp.open("POST", "http://www.fullDomainNameHere.com/signup_server.php", true);
Re: Cannot send message using POST
No. The URL does not have to be root based. It is simply relative to the currently viewed page's path.
If you were correct, the user would not have gotten any server response back.
Re: Cannot send message using POST
I am unable to test AJAX-PHP codes because of the problem (or feature) of Firefox as per post #3 in this thread. I'll be grateful if anyone can solve this problem.
Re: Cannot send message using POST
Re: Cannot send message using POST
Please do not post similar questions around multiple forums. Since this is the same issue, it belongs here.
Now, concerning your problem...this has been experienced by many people who run PHP on IIS. Maybe you should take a look here. Does that help?
Re: Cannot send message using POST
Sorry for the double post. The link you provided seems broken to me. I cannot open the page. Anyway, thanks.
Re: Cannot send message using POST
Works perfectly fine. Firewall blocking it?
Re: Cannot send message using POST
oh! that was because my net speed was too slow at that time. however, my problem was in my office computer. i will check it out there next week. thanks.