-
March 25th, 2008, 01:46 AM
#1
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.
~Donotalo()
-
March 25th, 2008, 07:15 AM
#2
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.
-
March 27th, 2008, 04:14 AM
#3
Firefox Authentication
I am using IIS 5.1 on Windows XP SP2. When I try to access a php file (using AJAX, a normal php file loads) through firefox 2, firefox wants authentication. After googling I tried several tweaks in about:config, but neither works. This authentication appears in IE 6 too. Most annoying part is, when I enter username and password that I use to log in to Windows, Firefox again pops up same dialog box asking username and password and IE does nothing after entering username and password.
How to get rid of this annoying pop up? Thanks in advance.
~Donotalo()
-
March 27th, 2008, 10:54 AM
#4
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);
-
March 27th, 2008, 11:16 AM
#5
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.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
March 27th, 2008, 12:37 PM
#6
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.
Last edited by PeejAvery; March 27th, 2008 at 12:56 PM.
Reason: Corrections for merged thread.
~Donotalo()
-
March 27th, 2008, 12:57 PM
#7
Re: Cannot send message using POST
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
March 27th, 2008, 01:03 PM
#8
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?
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
March 28th, 2008, 12:51 AM
#9
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.
~Donotalo()
-
March 28th, 2008, 06:48 AM
#10
Re: Cannot send message using POST
Works perfectly fine. Firewall blocking it?
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
March 28th, 2008, 11:10 AM
#11
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.
~Donotalo()
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|