SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict
    Join Date
    Jul 2004
    Location
    Brooklyn, NY
    Posts
    316
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Server returns 503, why?

    my code works fine on localhost, but once I upload it the server always returns a 503 error
    I tried to run the server page manually and everything worked fine, so the problem is somewhere within the xmlhttprequest

    here is my javascript code:
    Code:
    function submit(){
    document.getElementById('submit').style.display='none';
    var request=(window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
    if(request){
    	var name=document.getElementById('name').value;
    	var email=document.getElementById('email').value;
    	var comment=document.getElementById('comment').value;
    	request.onreadystatechange = function() { thanks(request); };
    	request.open('POST', 'submit.php?&name='+name+'&email='+email+'&comment='+comment, true);
    	request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    	request.send(null);
    	}
    }
    
    function thanks(request){
    if (request.readyState == 4) {
        if (request.status == 200) {
    		document.getElementById('form').style.display='none';
    		document.getElementById('thanks').style.display='inline';
    		}
        }
    }
    here is my server code:
    PHP Code:
    include("connect.php");
    $date=date("M jS, Y");
    $name=$_GET['name'];
    $email=$_GET['email'];
    $comment=$_GET['comment'];
    $query="INSERT INTO comments VALUES(id, '$date', '".mysql_real_escape_string($name)."','".mysql_real_escape_string($email)."','".mysql_real_escape_string($comment)."')";
    mysql_query($query) or die(mysql_error());
    echo 
    "Complete"
    if I manually go to submit.php and type in submit.php?name=blah&email=example@something.com&comment=hello and run that in the address bar, then everything is executed without errors. I really have no idea why it's not going through on the server but works okay on localhost

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    request.open('POST', 'submit.php?&name='+name+'&email='+email+'&comment='+comment, true);

    1) I'm assuming submit.php is in the same directory
    2) You have no domain information, you'll get access denied issues, prepend http://www.yoursite.com/ and any path information before submit.php. See:

    http://www.sitepoint.com/forums/showthread.php?t=384797

    item #2 for details.

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    When you pass the parameters on the end of the URL that is a GET request. A POST request passes the info in the send (where you are currently sending null instead of the data that you want to pass).
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall
    When you pass the parameters on the end of the URL that is a GET request. A POST request passes the info in the send (where you are currently sending null instead of the data that you want to pass).
    Then how come it works on his localhost?

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Obviously they are running on different operating systems or different web servers or different versions of the server side language (or all three) and the combination being run locally allows this to work while the combination running on the hosting account expects the post variables to be passed in the right place.

    Try changing the POST to GET and see what effect that has.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    SitePoint Addict
    Join Date
    Jul 2004
    Location
    Brooklyn, NY
    Posts
    316
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall
    Obviously they are running on different operating systems or different web servers or different versions of the server side language (or all three) and the combination being run locally allows this to work while the combination running on the hosting account expects the post variables to be passed in the right place.

    Try changing the POST to GET and see what effect that has.
    okay, I gave it a try and it worked with GET

    on localhost I'm running Win2003 + PHP5 + apache2
    on server they're running FreeBSD + PHP5 + apache1.3


    what is the correct way of doing this with POST?

  7. #7
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what is the correct way of doing this with POST?
    Code:
    request.open('POST', 'submit.php', true);
    request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    request.send('name='+name+'&email='+email+'&comment='+comment);

  8. #8
    SitePoint Addict
    Join Date
    Jul 2004
    Location
    Brooklyn, NY
    Posts
    316
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    great, got everything to work!
    thanks for your help everyone


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •