如何使$ .get()函数在jQuery中同步? [英] How to make $.get() function synchronous in jQuery?
本文介绍了如何使$ .get()函数在jQuery中同步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使$ .get()方法在我的函数中同步.在ajax中,aysnc : false
可以帮助我,现在我该如何对$.get()
I want to make $.get() method synchronous in my function. In ajax aysnc : false
helps me, now how do i do the same to to $.get()
var ifsc_code = $('#ifsc-code').val();
var api_url = 'http://api.techm.co.in/api/v1/ifsc/'+ifsc_code;
$.get(api_url, function(data, status){
//console.log(data.status);
var status = data.status;
if (data.status == "success") {
$.each(data,function(key,value){
var address = value.BANK+", " + value.BRANCH+", " + value.ADDRESS ;
$('.bank-details').removeClass('no-ifsc').text(address);
});
var res = "true";
alert('inside checkIfsc true');
return res;
}
else if (data.status == "failure") {
$('.bank-details').addClass('no-ifsc').text(data.message);
var res = "false";
alert('inside checkIfsc false');
return res;
}
还是有其他方法可以做到这一点?
Or is there any other approach to do the same ?
推荐答案
$ .get 也接受这样的参数
$.get({
url: url,// mandatory
data: data,
success: success,
dataType: dataType,
async:false // to make it synchronous
})
这篇关于如何使$ .get()函数在jQuery中同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文