如何讓jQuery執(zhí)行同步而非異步的Ajax請求?我有一個(gè)JavaScript小部件,它提供標(biāo)準(zhǔn)的擴(kuò)展點(diǎn)。其中之一就是beforecreate功能。它應(yīng)該返回false以防止創(chuàng)建項(xiàng)目。我使用jQuery在這個(gè)函數(shù)中添加了一個(gè)Ajax調(diào)用: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);
});}但我想阻止我的小部件創(chuàng)建項(xiàng)目,所以我應(yīng)該返回false母函數(shù),而不是回調(diào)。有沒有辦法使用jQuery或任何其他瀏覽器中的API執(zhí)行同步AJAX請求?
如何讓jQuery執(zhí)行同步而非異步的Ajax請求?
慕尼黑8549860
2019-05-29 17:05:12