ajax - jQuery timeout: e.nodeName is undefined -
<script type="text/javascript"> var delay = (function() { var timer = 0; return function(callback, ms) { cleartimeout(timer); timer = settimeout(callback, ms); }; })(); $(function() { $('#activity').change(function() { $(this).val() == "sid" ? $('.sidcontainer').show() : $('.sidcontainer').hide(); }); $('.sid').keyup(function() { delay(function() { $.ajax({ url: '../sentineloperationsui/generichandler.ashx', data: { 'sid': $(this).val() }, datatype: 'json', success: function(data) { if (data.sid != null) { $('.sidresult').text('match: ' + ' sid: ' + data.sid); console.log(data); } } }); }, 500); }); });
the code works without delay function. want delay here because otherwise multiple ajax request might sent same value (if type fast enough). idea might causing this? other solutions on problem maybe? thanks
instead of using delay, why not assign ajax call variable, check null each new keyup event. like:
var ajaxcall; $('.sid').keyup(function() { if ( ajaxcall != null ){ ajaxcall.abort(); } ajaxcall = $.ajax({ url: '../sentineloperationsui/generichandler.ashx', data: { 'sid': $(this).val() }, datatype: 'json', success: function(data) { if (data.sid != null) { $('.sidresult').text('match: ' + ' sid: ' + data.sid); console.log(data); } } }); });
this ensure every keyup action span new ajax event , cancel previous one.
Comments
Post a Comment