简体   繁体   English

jQuery.Form不会提交

[英]jQuery.Form wont submit

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´ma newbie) (我是新手)

jQuery 1.4.2 and the jQuery Form Plugin 2.43 is present. 存在jQuery 1.4.2和jQuery Form Plugin 2.43。

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

You are missing quotation marks in your url attribute: 您在url属性中缺少引号:

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

needs to be 需要是

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

that leads to a JavaScript error. 导致JavaScript错误。 Errors in the onsubmit function make the browser fall back to default behaviour (ie send the form the normal way). onsubmit函数中的错误使浏览器退回到默认行为(即,以正常方式发送表单)。

And as @jAndy points out, post needs some quotes as well. 正如@jAndy指出的那样, post需要一些引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM