jquery - How to return result from function that has an $.ajax call -
jquery - How to return result from function that has an $.ajax call -
i'll right off bat this question seems address same situation, life of me i'm not seeing solution/answer there. perhaps needs "spell out" more me!
i have next function:
function checkifurlexists(checkurl) { var exists = ''; $.ajax({ type: 'post', url: '../scripts/branchadmin.php', data: {checkurl: checkurl}, cache: false, success: function(response) { console.log('response: ' + response); if (response === 'true') { exists = 'true'; } else if (response === 'false') { exists = 'false'; } }, error: function(response) { // homecoming false , display error(s) server exists = 'false'; } }); console.log('exists: ' + exists); // displays empty string, regardless of php script returns homecoming exists; }
and i'm calling this:
var exists = checkifurlexists($tr.find('input.editurl').val()); if (exists === 'false') { //if (!checkifurlexists($tr.find('input.editurl').val())) { // new url entered, verify user want save $('#confirmaddnewurldialog').data('row', $tr).dialog('open'); ... // code handle result }
how can "checkifurlexist() function homecoming true or false (or value matter) can utilize in above code?
make ajax phone call async alternative false. you'll result. see link http://stackoverflow.com/a/1531710/399414
$.ajax({ type: 'post', async: false, url: '../scripts/branchadmin.php', ...
function jquery return-value
Comments
Post a Comment