2

Here is the code for the jquery:

<script type="text/javascript"> 
    $(document).ready(function(){
        $('#room').submit(function(){
            $.post('backend/CreateRoom.php', $('#room').serialize() ,function(data) {
                alert(1);
                $('#llama').append(data);
                console.log('working');
            });
        });
        return false;
     }); 
</script>

The function part does not seem to be working. The PHP code on the backend/CreateRoom.php seems to work fine(the code updates a PHP database) works fine, it just doesnt update the div, or do anything I put in the function. Help?

Colin Brock
  • 21,267
  • 9
  • 46
  • 61
  • What does the server respond with? `200 OK` ? – alex Dec 23 '11 at 00:30
  • Do you see the message with "1" on the screen? – Kath Dec 23 '11 at 00:32
  • try adding .error(function() { alert("error"); }) at the end of you $.post statement. Look for "error" on [jquery post API](http://api.jquery.com/jQuery.post/) and you should be able to debug it easily – Shoogle Dec 23 '11 at 00:41

1 Answers1

1

Looks like you are returning false on document ready. I think you want that on submit.

$(document).ready(function(){
    $('#room').submit(function(){
        $.post('backend/CreateRoom.php', $('#room').serialize() ,function(data) {
            alert(1);
            $('#llama').append(data);
            console.log('working');
        });
     return false;
    });

});

or prevent default:

$(document).ready(function(){
    $('#room').submit(function(event){
        event.preventDefault();
        $.post('backend/CreateRoom.php', $('#room').serialize() ,function(data) {
            alert(1);
            $('#llama').append(data);
            console.log('working');
        });
    });
});
jk.
  • 14,365
  • 4
  • 43
  • 58
  • Dont forget `e.returnValue = false;` for IE7/8 – Steve Robbins Dec 23 '11 at 01:07
  • @stevether Thanks. News to me. It may just be mootools, still looking for jquery example. For my example it's `event.returnValue = false` and further explanation here: [event.preventDefault() function not working in IE.](http://stackoverflow.com/questions/1000597/event-preventdefault-function-not-working-in-ie-any-help) – jk. Dec 23 '11 at 01:10