开发者

jquery function is not a function

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜