javascript - jquery function returns true but cannot process the return value -


this question has answer here:

hi guys here code function checks if id present in database

function checkifuploaded(citenr) {         $.ajax({             type: "post",             url: "locationsdb.asmx/checkifexist",             data: '{"citenr": "' + citenr + '"}',             contenttype: "application/json; charset=utf-8",             datatype: "json",             success: function (response) {                 if (response.d) {                      return true;                  } else {                      return false;                 }                  //setinfo();             },             failure: function (response) {                 alert(response.d);             }          });     } 

now have function using function above

function plotnew(lat, lng) {              $('#latt').val(lat);             $('#longt').val(lng);             $("#panel2").dialog({                 resizable: false,                 height: 350,                 width: 600,                 modal: true,                 buttons: {                     "plot incident , save database": function () {                         //$(this).dialog("close");                         if (checkifuploaded($('#idcr').val())) {                             $.post(                                     'insertcrimelocation.aspx',                                     { lat: $('#latt').val(), long: $('#longt').val(), cirsid: $('#idcr').val() },                                     function (responsetext, textstatus) {                                         //checkifexist                                          plot();                                          $("#panel2").dialog("close");                                         $.ambiance({ message: "successfully plotted incident!",                                             title: "success!",                                             type: "success"                                         });                                       })                                     .error(function () {                                         $.ambiance({ message: "error on request",                                             title: "error!",                                             type: "error"                                         });                                     });                         } else {                             $.ambiance({ message: "the c.i.r.s id not yet uploaded",                                 title: "error!",                                 type: "error"                             });                         }                       },                     cancel: function () {                         $(this).dialog("close");                     }                 }             });           } 

my webservice code below returns expected returns true

<webmethod()> _     public function checkifexist(citenr string) boolean         dim locs new crimemsapslocationdatacontext         dim check = locs.offenses.where(function(offense) offense.cite_nr = citenr).first         if not check nothing             return true         else             return false         end if      end function 

what amazes me on second function namely plotnew() if return value true executes other way around instead of calling function trough page there wrong code?

i got work code below

function checkifuploaded(citenr) {         $.ajax({             type: "post",             url: "locationsdb.asmx/checkifexist",             data: '{"citenr": "' + citenr + '"}',             contenttype: "application/json; charset=utf-8",             datatype: "json",             success: function (response) {                 if (response.d) {                      squeezed function here make work                     , info                  } else {                      return false;                 }                  //setinfo();             },             failure: function (response) {                 alert(response.d);             }          });     } 

you can use promise object handle asynchronous processing. http://api.jquery.com/jquery.ajax/


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -