Note that there are some explanatory texts on larger screens.

plurals
  1. POEvent is sometimes triggered more than once
    text
    copied!<p>I use the jQuery ajax function to send data to 2 php scripts. The first script inserts the received data into a MySQL db, the second sends emails. The ajax functions are attached to a click event. For some unknown reason sometimes there are 2 or 3 database entries and sent emails even if I click only once. As you can see the 2nd ajax call is embedded into the first one. I tried to use them in parallel. Tried without 'set timeout'-s. I also use here the simplemodal plugin. When the first modal closes, the second opens.</p> <p>Is there a way to make sure that the click event is triggered only once or to block the ajax requests after 1 successfull call?</p> <p>Here is a part of the code: </p> <pre><code>$('#confirm').click(function () { $('#loading').html("&lt;img style = 'display:inline-block;' src = 'img/loading.gif' /&gt;"); var servtype = $('select option:selected').text(); $('#type').text(servtype); $('#staff_name').text(staff_name); $('#day_time').text(a); $('#day_date').text(nap + ', ' + dateText); $('#type1').text(servtype); $('#staff_name1').text(staff_name); $('#day_time1').text(a); $('#day_date1').text(nap + ', ' + dateText); var message = $('#message').val(); $.ajax({ type: 'GET', async: true, url: 'add_booking.php', data: 'message=' + message + '&amp;date=' + dateText + '&amp;start_end=' + a + '&amp;personid=' + personid + '&amp;servid=' + servid, success: function (msg) { var obj = jQuery.parseJSON(msg); alert('' + obj.answer); setTimeout(function () { $.ajax({ type: 'GET', async: true, url: 'send_email.php', data: 'email=zolkazlk@gmail.com&amp;type=' + servtype + '&amp;person=' + staff_name + '&amp;time=' + a + '&amp;date=' + nap + ', ' + dateText, success: function (msg) { var obj = jQuery.parseJSON(msg); alert('' + obj.answer); $.modal.close(); window.setTimeout(function () { jQuery('#receipt').modal() }, 50); } }); }, 200); } }); }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload