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.
精彩评论