javascript - return value after callback function Not Working -


this question has answer here:

i don't know below valid question? or stupidity.

 function isslaexists(department) {      var flag = "";      $.ajax({          type: "post",          data: "type=isslaexists&department=" + encodeuri(escape(department)),          url: "class-accessor.php",          success: function (data) {              //flag=data;                flag = "yes";          }      });      return flag;  }   alert(isslaexists('department')); 

i'm trying return value of flag function returns blanks if set value of flag maually. i'm doing wrong?

$.ajax({        type: "post",        data: "type=isslaexists&department=" + encodeuri(escape(department)),        url: "class-accessor.php" }).done(function(r){       alert("flag"); }); 

this give alert when ajax request successfull. r contain data response got you. can now, example, call function inside done function process request.

since $.ajax returns promise, return ajax call , chain functions together

function ajaxcall(department) {     return  $.ajax({            type: "post",            data: "type=isslaexists&department=" + encodeuri(escape(department)),            url: "class-accessor.php"     }); }  ajaxcall("mydept").done(function(response){    alert(response); }) 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -