DEV Community

Discussion on: How to send Django form with AJAX

Collapse
 
cswinslow profile image
Chris Winslow

"If you have more than one form in your page you can separate them by using action, so your view will not get multiple requests at the same time."

Any chance we can get an example of this? Like: how does the view.py code change to accommodate this, and how does the .js also change? I've experimented a bit, but I'm kind of lost.

Collapse
 
enesislam profile image
enesstr • Edited

what about "data-name" attr? You can assigment an attribute that starts with "data-" to separate forms in ajax section.
For instance:

//html

li data-animal-type="fish">Salmon>/li>

//js
"""
data: {'content_id': $(this).attr('data-animal-type'),
'operation':'add_new_animal',
//We will got "fish" value.

"""

w3schools.com/tags/att_data-.asp