Hello. I have a form inside a modal - which is opened by clicking a button that is generated as a column of a table. By clicking on this button I will capture the contents of each column and fill out a form in the modal.
If I edit this form or not, it will be sent to a php script to update the data of a given user - all via ajax. In the ajax function, when I return success, I am comparing if the result is equal to 'abc' then , and if it is, I call the Notify function - which generates a small notification.
The plugin for the notification is: Notify .
I have two problems.
I'm getting values as parameter = value & parameter2 = value2 & parameter3 = value3, but besides sending the form, I want to send a numeric value but I can not get the values in the php script ... So:
var dados = $('form[name=ajax_form]').serialize();
var arry = {userId: id, formData: dados}
My html-table:
the formation of the table within a while ...
<td>
<button class="edit-user" data-toogle="modal" data-target="#modal-warning" data-id = <?php echo resultadoQuery['id']; ?>data-email = <?php echo $linhaAssociativa["email"];?> data-nome = "<?php echo $linhaAssociativa["nome"];?>" data-username = <?php echo $linhaAssociativa["login"];?>>
<i class="fa fa-pencil" aria-hidden="true"></i>
</button>
</td>
My modal-html:
In the modal-body a common form with 3 inputs: name, email and username ... At the end of the form a button to submit to the script that contains ajax.
<button type="submit" class="btn btn-primary"name="enviar">Enviar</button>
My javascript-ajax: The function that contains the entire ajax bid is called when that button I mentioned at the beginning (regarding each line).
$(document).on('click', '.edit-user', function(){
var $this = $(this);
var usuario = $this.attr('data-username');
var email = $this.attr('data-email');
var nome = $this.attr('data-nome');
What I noticed: When I click on the button and open the modal and click Send (which is the modal submit button), I can see the request made in Network / XHR. Without closing the modal and clicking submit again, one more edit-user.php is added to the history with status 200.
But if I close the modal, and click the button to open the modal again and click send, two requests are sent and two edit-user.php + the previous ones appears in the history! Now if I close again, and open the modal and click submit, the previous ones appear and + 4 edit-user.php ... As if every time I open the modal window from the button it accumulated the requests and sent everything again!