I would think that a form object would be filled with format and formation.
Question: Is there a way to get the formula? Or find out which button in the form was pressed to open them with the button?
Do I need to rewrite the event handler in order to catch clicks on the button ( $(document).on('click', '.myformbtn', function(e)) and use it var queryString= $(this).parent('form').serialize();to access the form.
<form>
<button type="submit"
formmethod="POST"
formaction="/mysave">Save</button>
<button type="submit"
formmethod="GET"
formaction="/mydata">Get new data</button>
</form>
$(document).ready(function()
{
$(document).on('submit', 'form', function(e) {
e.preventDefault();
var formaction = $(this).getFormAction();
var queryString= $(this).serialize();
$.ajax({
type: formmethod,
url: formaction,
data: queryString
});
});
});
I found similar questions, and the answer is always $(this).attr('formaction')that is incorrect, since the form does not have this attribute. I hope that an example of how it will be used will make people's brains work.
source
share