Arsenii
Arsenii

Reputation: 784

How to get data from form using JS, when the form has been returned from AJAX itself?

Here we have a <div id="content"> and inside it AJAX loads data from the server. We have preloaded JS scripts in the whole file. Some of the server's AJAX answers are whole forms. That forms have the same ids, but different structures. What is needed is to pick the data from freshly baked forms came from the server via AJAX, using JavaScript and create a kinda queryString to send its data again to the server via AJAX itself. What has been tried:

I am new in AJAX so, please, do not judge me with all the severity. Thanks!

Upvotes: 0

Views: 56

Answers (1)

Sarath Chandra
Sarath Chandra

Reputation: 1888

If your issue is picking up only the latest baked forms, you can try the following approach:-

  1. In each ajax call of the page, before setting the response content to the desired div, find all objects having class name called 'lastUpdated' (or any other unique class name that you can come up with) and remove all the lastUpdated class associations using the jQuery code $('.lastUpdated').removeClass("lastUpdated");
  2. Now set the response to the desired div and add the class 'lastUpdated' to this div alone.

Thus at any point of time,

$('.lastUpdated')

will help you pick the data from freshly baked forms came from the server

Upvotes: 1

Related Questions