I'm trying submit some form using ajax
//include jquery-1.4.2.min.js
var submitForm = document.createElement("FORM");
...
j开发者_开发问答Query.post(submitForm.getAttribute('action'), submitForm.serialize(), function(data) {
bla-bla
});
But there is error : "Error: submitForm.serialize is not a function" (FF)
What can I do? Thanks.
submitForm
is a DOM element, so you need to wrap it in a jQuery object to user jQuery methods like .serialize()
on it, like this:
jQuery(submitForm).serialize()
Create the form element with jQuery instead.
var submitForm = jQuery("<form />");
/* set attributes using attr */
// use attr instead of getAttribute
jQuery.post(submitForm.attr('action'), submitForm.serialize(), function(data) {
bla-bla
});
精彩评论