1

I'm trying submit some form using ajax

//include jquery-1.4.2.min.js
var submitForm = document.createElement("FORM");
...
jQuery.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.

3
  • Im create form using javascript. Commented Oct 12, 2010 at 20:04
  • @Stas: Create the element using jQuery instead. Updated my answer. Commented Oct 12, 2010 at 20:08
  • Thanks. Thread will be closed) Commented Oct 12, 2010 at 20:08

2 Answers 2

3

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()
Sign up to request clarification or add additional context in comments.

Comments

2

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

1 Comment

Creating element with jQuery: api.jquery.com/jQuery --- jQuery attr: api.jquery.com/attr

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.