如何让jQuery执行同步而不是异步的Ajax请求?

问题:

I have a JavaScript widget which provides standard extension points. 我有一个提供标准扩展点的JavaScript小部件。 One of them is the beforecreate function. 其中之一是beforecreate函数。 It should return false to prevent an item from being created. 它应该返回false以防止建立项目。 node

I've added an Ajax call into this function using jQuery: 我已经使用jQuery在此函数中添加了Ajax调用: 浏览器

beforecreate: function (node, targetNode, type, to) {
  jQuery.get('http://example.com/catalog/create/' + targetNode.id + '?name=' + encode(to.inp[0].value),

  function (result) {
    if (result.isOk == false) 
        alert(result.message);
  });
}

But I want to prevent my widget from creating the item, so I should return false in the mother-function, not in the callback. 可是我想防止个人小部件建立项目,所以我应该在母函数中而不是在回调中返回false Is there a way to perform a synchronous AJAX request using jQuery or any other in-browser API? 有没有一种方法能够使用jQuery或任何其余浏览器内API执行同步AJAX请求? 异步


解决方案:

参考一: https://stackoom.com/question/YgA/如何让jQuery执行同步而不是异步的Ajax请求
参考二: https://oldbug.net/q/YgA/How-can-I-get-jQuery-to-perform-a-synchronous-rather-than-asynchronous-Ajax-request
相关文章
相关标签/搜索