javascript - Ajax Uncaught TypeError: in simple function -


in code getting error

uncaught typeerror: cannot read property 'tolowercase' of undefined

but when remove

delay(function(){ ... }, 1000); 

from source file code works don't know doing wrong or missing important do, here full code

function checkurl(textname) { $.ajax({     type: "post",     url: "includes/modcontent/checkurl.php",     data: "checkurl=" + textname,     datatype:'text', //or html, json, etc.     success: function(response){         //alert(response);         textname = response;         }     });     return textname; }  $('input[name=txtpagename]').keyup(function() {     delay(function(){       $('input[name=txtseourl]').val(checkurl($(this).val()));     }, 1000); });  var delay = (function(){   var timer = 0;   return function(callback, ms){     cleartimeout (timer);     timer = settimeout(callback, ms);   }; })(); 

the immediate issue, amongst others, you're changing scope of this when pass callback settimeout() handler.

to fix issue need invert logic set val() of field when ajax completes instead of using convoluted method of attempting return data async function. try this:

var timeout; $('input[name="txtpagename]"').keyup(function() {   cleartimeout(timeout);   var textname = $(this).val();    settimeout(function() {     $.ajax({      type: "post",       url: "includes/modcontent/checkurl.php",       data: { checkurl: textname },       datatype: 'text',       success: function(response) {         $('input[name=txtseourl]').val(response.trim());       }     });   }, 250); }); 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -