开发者

jQuery.Form wont submit

开发者 https://www.devze.com 2023-01-02 07:47 出处:网络
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.

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

        // !!! Im开发者_如何学运维portant !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
    }); 
}); 


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号