javascript - jQuery.Form 不会提交

标签 javascript jquery

我尝试在不刷新页面的情况下提交表单,但遇到问题。 当我单击“提交”时,页面会刷新并发布任何内容。 这是代码,我做错了什么? (我是新手)

存在 jQuery 1.4.2 和 jQuery 表单插件 2.43。

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

最佳答案

您的 url 属性中缺少引号:

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

需要

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

这会导致 JavaScript 错误。 onsubmit 函数中的错误会使浏览器回退到默认行为(即以正常方式发送表单)。

正如 @jAndy 指出的,post 也需要一些引号。

关于javascript - jQuery.Form 不会提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2988714/

相关文章:

javascript - 如何在 openSUSE 上使用 NGINX 或 Apache2 将端口 80 重新路由到 localhost :3000 so I can run my Node. js 应用程序

javascript - Ajax jqXHR.status==0 修复错误

javascript - 用于种子随机数生成的 MD5,更好的方法?

jquery - 在 Angular 中循环 json

javascript - 在新窗口中打开新页面,打印并关闭

javascript - 取消选中父上下文中的复选框

具有动态开始和结束变量的 JavaScript 循环

javascript - 显示 float Div 而不是下拉列表的选择项内容列表

javascript - 使用 JavaScript 或 Jquery 自动完成输入文本

Javascript 正则表达式替换 HTML 标签