0
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 this button I capture the contents of each column and fill a form inside the modal.
Whether or not I edit this form, it will be sent to a php script to update the data of a particular user - all via ajax. In the ajax function, when returning 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 notification is: Notify.
I’m in two trouble.
- By clicking 'Send' inside the modal-form the data is successfully sent to the php script. However, if I close the modal, open again, fill in the form and click submit, the notification appears twice. If I do this a third time, the notification will appear three times and so on.
I am receiving the values as parameter=value¶meter 2=value2¶meter3=Valor3, but in addition to submitting the form, I want to send a numerical value, but I am not able to capture the values in the php script... Thus:
var dados = $('form[name=ajax_form]').serialize(); var arry = {userId: id, formData: dados}
My table-html:
table formation 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:
formation of a common modal-bootstrap... and within 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 containing ajax.
<button type="submit" class="btn btn-primary"name="enviar">Enviar</button>
My javascript-ajax is: The function containing the whole ajax throw is called when that button I quoted 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 could notice: By clicking on the button and opening the modal and clicking on Submit (which is the modal’s Ubmit button) I can see in Network/XHR the request made straight. Without I close the modal and click submit again, an Edit-user.php is added to the history with 200 status.
But if I close the modal, and I click on the button to open the modal again and click on send, two requests are sent and two Edit-user.php + previous ones appear in the history! Now if I close again, and open the modal and click submit, appears the previous and + 4 Edit-user.php... As if every time I open the modal window from the button it accumulates the requests and sends them all over again!
Good afternoon, well explained, but "TLDR". The idea I had is to do a test by opening and sending in a new browser. If something is different it could be "Cache, Cookie, Sessions", I could be completely wrong...
– MagicHat
If I put little information to the bag, if I put something very complete, with what I did and how far I got, presenting the bugs also fill the bag? Blah
– Cesar Augusto
Hehe, relax bro I know how it is... I spoke only my vision, but I can and must be wrong (analyzing the job you had to ask this question), the same way I stopped to read and understand it, others can do. Rest assured, malz ae... Num had seen by this point.
– MagicHat