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