Hello I have problem return a value in function using ajax, And I am solved problem after search in google.com and recomend from stackoverflow. So, in my case only add async : false in function ajax.
function insert(data_nya){ let returnStatus = false; $.ajax({ method: 'POST', url: "<?= base_url(); your_controller ?>", data: data_nya, async: false, // add async for return value variable returnStatus. success: function(res){ let data_nya = $.parseJSON(res); if(data_nya.status_insert == 2){ returnStatus = true; }else{ returnStatus; } } }); // end ~ ajax return returnStatus; } // end ~ function
Enjoy it. ^_^
TAG TAGS :
return value ajax || How to return value ajax from function || ajax || how to return value from function ajax || jquery || ajax
langsungkoding.blogspot.com |
langsungkoding |
REFERENCE :