Note that there are some explanatory texts on larger screens.

plurals
  1. POweird problem - change event fires only under debug in IE
    primarykey
    data
    text
    <p>I have form autocomplete code that executes when value changes in one textbox. It looks like this: </p> <pre><code>$('#myTextBoxId)').change(function () { var caller = $(this); var ajaxurl = '@Url.Action("Autocomplete", "Ajax")'; var postData = { myvalue: $(caller).val() } executeAfterCurrentAjax(function () { //alert("executing after ajax"); if ($(caller).valid()) { //alert("field is valid"); $.ajax({ type: 'POST', url: ajaxurl, data: postData, success: function (data) { //some code that handles ajax call result to update form } }); } }); }); </code></pre> <p>As this form field (myTextBoxId) has remote validator, I have made this function:</p> <pre><code>function executeAfterCurrentAjax(callback) { if (ajaxCounter &gt; 0) { setTimeout(function () { executeAfterCurrentAjax(callback); }, 100); } else { callback(); } } </code></pre> <p>This function enables me to execute this autocomplete call after remote validation has ended, resulting in autocomplete only when textbox has valid value. <code>ajaxCounter</code> variable is global, and its value is set in global ajax events:</p> <pre><code>$(document).ajaxStart(function () { ajaxCounter++; }); $(document).ajaxComplete(function () { ajaxCounter--; if (ajaxCounter &lt;= 0) { ajaxCounter = 0; } }); </code></pre> <p>My problem is in IE (9), and it occurs only when I normally use my form. Problem is that function body inside executeAfterCurrentAjax(function () {...}); sometimes does not execute for some reason. If I uncomment any of two alerts, everything works every time, but if not, ajax call is most of the time not made (I checked this by debugging on server). If I open developer tools and try to capture network or debug javascript everything works as it should.</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.
 

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