开发者

jquery function is not a function

开发者 https://www.devze.com 2023-01-19 22:07 出处:网络
I\'m trying submit some form using ajax //include jquery-1.4.2.min.js var submitForm = document.createElement(\"FORM\");

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

精彩评论

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