Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2007
    Location
    Seattle, WA
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs down Help. me. before. I. become. [drama]

    Ajax is out there to k((i((l((l)) me. D:

    edit.php
    Code:
    ...
    ajaxRequest.onreadystatechange = function(){
        if(ajaxRequest.readyState == 4){
            document.write("<center>"+ajaxRequest.responseText"</center><br>")
        }
    }
        var name = document.getElementById('name').value;
        var description = document.getElementById('description').value;
        var query = "&name="+name"&description="+description"";
        xmlHttp.Request.open("GET","edit_ss.php"+query,true);
        xmlHttp.Request.send(null);
      }
    </script>
    <?php
    echo "<b>Note:</b> 'Last Name' needs to be ONE letter - Please start filling these in!</b>";
    echo "<form id='thing'>";
    echo "Name <input type='text' id='name'><br><br>Description<br><textarea cols=80 rows=10 value='".$row['description']."' id='description'></textarea><br><br><input type=submit value=Update! onClick='javascript: ajaxFunction()'></form>";
    ...
    What's wrong with this?! I know I'm not a javascript guru..>_> But yeah. The code on "edit_ss.php" is correct; It GET's the vars and updates the DB with them.
    Although this form just clicks and reloads the page.. and then doesn't update. x.x

    [PS: The thumgs down is for how bad ajax can be to poor newbs. =p]
    -TCD
    Josh/12/PHP/MySQL/Some Javascript/Some AJAX/HTML/CSS/Some Photoshopping/Learning C++

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    To stop the form from reloading the page change the input type="submit" to type="button", or return false to stop the submit.

    You will also have to change how you are handling the response.

    Use a target element, like a division, span or paragraph and then access it by it's id:
    Code:
        if(ajaxRequest.readyState == 4){
            document.getElementById('results').innerHTML="<center>"+ajaxRequest.responseText"</center><br>";
        }
    
    
    ....
    
    
    
    ... <input type=button value=Update! onClick='javascript: ajaxFunction()'></form>";
    ...
    <div id="results"></div>


  •  

    Posting Permissions

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