是否可以将 async:false 设置为 $.getJSON 调用 [英] Is it possible to set async:false to $.getJSON call

查看:43
本文介绍了是否可以将 async:false 设置为 $.getJSON 调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在调用 $.getJSON() 时设置 async: false 以便调用阻塞而不是异步?

Is it possible to set async: false when calling $.getJSON() so that the call blocks rather than being asynchronous?

推荐答案

您需要使用 进行调用$.ajax() 同步到它,像这样:

You need to make the call using $.ajax() to it synchronously, like this:

$.ajax({
  url: myUrl,
  dataType: 'json',
  async: false,
  data: myData,
  success: function(data) {
    //stuff
    //...
  }
});

这将匹配当前使用 $.getJSON()像这样:

This would match currently using $.getJSON() like this:

$.getJSON(myUrl, myData, function(data) { 
  //stuff
  //...
});

这篇关于是否可以将 async:false 设置为 $.getJSON 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆