views:

57

answers:

1

Im´trying to submit a form without refreshing the page, but I´m having a problem. When I click submit the page refreshes and anothing gets posted. Here is the code, what am I doing wrong? (I´m a newbie)

jQuery 1.4.2 and the jQuery Form Plugin 2.43 is present.

tnx

$(document).ready(function() { 
    var options = { 
        target:        '#output2',
        url:       https://graph.facebook.com/<%=fbUid%>/feed,
        type:      post,

        clearForm: true        // clear all form fields after successful submit 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //resetForm: true        // reset the form after successful submit 

        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 

    // bind to the form's submit event 
    $('#fbPostStatus').submit(function() { 
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $(this).ajaxSubmit(options); 

        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
    }); 
}); 
+2  A: 

You are missing quotation marks in your url attribute:

 url:       https://graph.facebook.com/<%=fbUid%>/feed,

needs to be

 url:       "https://graph.facebook.com/<%=fbUid%>/feed",

that leads to a JavaScript error. Errors in the onsubmit function make the browser fall back to default behaviour (i.e. send the form the normal way).

And as @jAndy points out, post needs some quotes as well.

Pekka
Actually the error is in `ready`, so the submit handler doesn't even get hooked up.
T.J. Crowder
`post` needs some quotes aswell
jAndy
I have quoted post and the url, and the site stops reloading. And the form seems to submit (well, the textarea clears), but nothing gets posted. I must investigate.
kim
What is wrong with ready T.J?
kim