Jacek
Jacek

Reputation: 194

jQuery extract form data returned by Ajax call

I am doing an Ajax call to a page, which returns HTML containing a form. I need to extract and serialize this form, to perform another Ajax call using this form data in POST. How to accomplish this with jQuery?

Here's the example code:

jQuery.ajax({
  type: "POST",
  url: url,
  ...,
  success: function(data)
  {
     // "data" object contains HTML with a form
     // extract form data from "data" object
     // make another Ajax POST to another page, posting extracted form data
  },
  ...
});

Upvotes: 1

Views: 626

Answers (1)

Eternal1
Eternal1

Reputation: 5625

jQuery.ajax({
  type: "POST",
  url: url,
  ...,
  success: function(data)
  {
      var formData = $(data).find("form").serialize();
      $.post("/another/url", formData, callback);
  },
  ...
});

Upvotes: 2

Related Questions