Is it possible to set async:false to $.getJSON cal

2019-01-02 15:14发布

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

7条回答
只靠听说
2楼-- · 2019-01-02 16:15

Roll your own e.g.

function syncJSON(i_url, callback) {
  $.ajax({
    type: "POST",
    async: false,
    url: i_url,
    contentType: "application/json",
    dataType: "json",
    success: function (msg) { callback(msg) },
    error: function (msg) { alert('error : ' + msg.d); }
  });
}

syncJSON("/pathToYourResouce", function (msg) {
   console.log(msg);
})
查看更多
登录 后发表回答