Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to delay ajax query?
    primarykey
    data
    text
    <p>I read a lot of questions, but they doesn't working in my case. My situation is: my ajax query to database to insert infromation. But in my web-application user can click on buttons very quick so previous ajax query is not finished, and there is where bugs are appear. All i need to do is a delay between queries, so future queries will do only after previous is done. Here is a code:</p> <pre><code>$('#save').click(function(){ var user_input=$('#user').val(); var section=$('#section').val(); $('#loading_info').append('&lt;p&gt;&lt;img src="Images/loading.gif" alt="loading" id="loading"/&gt;&lt;/p&gt;'); $.ajax({ url: 'submit_db.php', type: 'POST', data: 'section='+section+'&amp;user_input='+user_input, success: function(result){ $('#response').remove(); $('#loading_info').append('&lt;p id="response"&gt;' + result + '&lt;/p&gt;'); $('#loading').fadeOut(500, function(){ $(this).remove(); }); } }); return false; }); </code></pre> <p>What i tested and not working: insert timeout:3000 into ajax - 1 query is ok, but after this, the whole application freezes; set timeout using ajaxSetup() - the same situation. Tested setInterval function and put ajax query to it - but after it there were no ajax, application opened an implementing php file and freezes.</p> <p><em>This not working:</em></p> <pre><code>$('#save').click(function(){ var t=setTimeout(function(){ var user_input=$('#user').val(); var section=$('#section').val(); $('#loading_info').append('&lt;p&gt;&lt;img src="Images/loading.gif" alt="loading" id="loading"/&gt;&lt;/p&gt;'); $.ajax({ url: 'submit_db.php', type: 'POST', data: 'section='+section+'&amp;user_input='+user_input, success: function(result){ $('#response').remove(); $('#loading_info').append('&lt;p id="response"&gt;' + result + '&lt;/p&gt;'); $('#loading').fadeOut(500, function(){ $(this).remove(); }); } }); return false; },3000); }); </code></pre> <p>And this is not working too:</p> <pre><code>$('#save').click(function(){ var user_input=$('#user').val(); var section=$('#section').val(); $('#loading_info').append('&lt;p&gt;&lt;img src="Images/loading.gif" alt="loading" id="loading"/&gt;&lt;/p&gt;'); $.ajax({ url: 'submit_db.php', type: 'POST', timeout: 3000, data: 'section='+section+'&amp;user_input='+user_input, success: function(result){ $('#response').remove(); $('#loading_info').append('&lt;p id="response"&gt;' + result + '&lt;/p&gt;'); $('#loading').fadeOut(500, function(){ $(this).remove(); }); } }); return false; }); </code></pre> <p>And finally this is not work too:</p> <pre><code>$.ajaxSetup({ timeout:3000, }); </code></pre> <p>Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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