CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Aug 2005
    Posts
    69

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

  2. #2
    Join Date
    Jun 2005
    Posts
    1,255

    Smile 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.

  3. #3
    Join Date
    Aug 2005
    Posts
    69

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

  4. #4
    Join Date
    Mar 2008
    Posts
    2

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

  5. #5
    Join Date
    May 2002
    Posts
    10,943

    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.

  6. #6
    Join Date
    Aug 2005
    Posts
    69

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

  7. #7
    Join Date
    May 2002
    Posts
    10,943

    Re: Cannot send message using POST

    [ merged ]
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  8. #8
    Join Date
    May 2002
    Posts
    10,943

    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.

  9. #9
    Join Date
    Aug 2005
    Posts
    69

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

  10. #10
    Join Date
    May 2002
    Posts
    10,943

    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.

  11. #11
    Join Date
    Aug 2005
    Posts
    69

    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
  •  





Click Here to Expand Forum to Full Width

Featured