Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
421 views
in Technique[技术] by (71.8m points)

javascript - How to make $.get() function synchronous in jQuery?

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

$.get also accepts parameter like this

$.get({
  url: url,// mandatory
  data: data,
  success: success,
  dataType: dataType,
  async:false // to make it synchronous
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...