我正在调用 AJAX 请求并获取结果,但直到那时下一行代码开始执行。我想保持直到 AJAX 成功块执行。
PFB 代码片段。
Ext.Ajax.request({
url: PORTALURL.EXCEPTION.MAX_VALUE,
success: function(response) {
var maxValue = Ext.decode(response.responseText);
if (grid.getSelectionModel().getSelection().length > maxValue) {
Ext.Msg.alert('Alert!', type + ' count is more than 10');
return;
}
}
});
CommonUtil.alertConfirm(msg, function() {
.. }
在上面的代码中。在 AJAX 请求完成并弹出警告框之前,
alertConfirm
被调用。
任何人都可以帮忙吗?
要等待 Ajax 响应,最好的方法是从 success 块中调用该函数。所以代码会在ajax响应得到之后被调用。
Ext.Ajax.request({
url: PORTALURL.EXCEPTION.MAX_VALUE,
success: function(response) {
var maxValue = Ext.decode(response.responseText);
if (grid.getSelectionModel().getSelection().length > maxValue) {
Ext.Msg.alert('Alert!', type + ' count is more than 10');
return;
}
// Call the required function which needs to be executed after ajax response.
CommonUtil.alertConfirm(msg, function() {
.. }
}
});
有这样一个属性允许请求变得同步。通过添加属性:
Ext.Ajax.request({
async: true,
// other properties for the request
});
更多内容可以在 Stackoverflow 对帖子的回答中找到这里。