javascript - jquery ajax deferred object not returning value -


i have code..

if (!checkifcustomerisvalid(event)) {         event.preventdefault();         return false;     } else {    addcustomer(); }  function checkifcustomerisvalid(event) {     if ($('#txtcname').val() == '') {         alert('please enter valid value customer name!');         return false;     }     if ($('#txtcaddress').val() == '') {         alert('please enter valid value customer address!');         return false;     }  } 

it returned fine, until then, added new check , not returning anything.

function checkifcustomerisvalid(event) {    // code there, name , address check    var _mobno;     if ($('#txtmobile').val() == '') return false;      var _unq = $.ajax({         url: '../autocomplete.asmx/ismobileunique',         type: 'get',         contenttype: 'application/json; charset=utf8',         datatype: 'json',         data: "mobileno='" + $('#txtmobile').val() + "'",         async: false,         timeout: 2000,         success: function (res) { if (res.d) return false; else return true; },         error: function (res) { alert('some error occurred when checking mobile no'); }     }),chained = _unq.then(function (data) { if (data.d == false) { alert('mobile no exists!'); $('#txtmobile').focus(); return false; } return true; });  } 

if mobile no not unique alert shows fine mobile no not unique, when is unique code doesn't go addcustomer (in else part)??? not returning true? why not going addcustomer???

with new test, checkifcustomerisvalid asynchronous. there no way it, deferred, directly return result of distant call.

the simplest here pass callback checkifcustomerisvalid function or return promise function. mix synchronous , asynchronous tests, best pass callback checkifcustomerisvalid.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -