Skip to content Skip to sidebar Skip to footer

Sending Form Via Ajax Everytime Clicked

I want to send my forms by click on each submit button. My question: How can i send each forms and indicate each result separately. I've tested the following code but it does not

Solution 1:

The only problem with your code is that your forms don't have .divs as their descendants. Please read the documentation of .find().

Get the descendants of each element in the current set of matched elements, filtered by a selector, jQuery object, or element.

Change your HTML to

<form>
  <button id="done"type="submit">done</button>
  <div class="divs"></div>
</form>
<form>
  <button id="done"type="submit">done</button>
  <div class="divs"></div>
</form>
<form>
  <button id="done"type="submit">done</button>
  <div class="divs"></div>
</form>

Now, if you press the done button, the corresponding form will trigger its submit event, which will be handled by jQuery. Also, as other answers pointed out, IDs for different elements have to be unique for an HTML page.

If you're just replacing the contents of the inner div, this line is sufficient.

$(this).find('.divs').html(data);

You don't need to empty the div first.

Post a Comment for "Sending Form Via Ajax Everytime Clicked"