Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
413 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 Answer

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
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...