如何在ExtJS中等待AJAX请求完成

uqxowvwt  于 2024-01-07  发布在  其他
关注(0)|答案(2)|浏览(223)

我正在调用AJAX请求并获得结果,但直到下一行代码开始执行。我想保持直到AJAX成功块执行。
PFB代码片段。

  1. Ext.Ajax.request({
  2. url: PORTALURL.EXCEPTION.MAX_VALUE,
  3. success: function(response) {
  4. var maxValue = Ext.decode(response.responseText);
  5. if (grid.getSelectionModel().getSelection().length > maxValue) {
  6. Ext.Msg.alert('Alert!', type + ' count is more than 10');
  7. return;
  8. }
  9. }
  10. });
  11. CommonUtil.alertConfirm(msg, function() {
  12. .. }

字符串
在上面的代码中,在AJAX请求完成并弹出警报框之前,alertConfirm被调用。
任何人都可以在这方面提供帮助。

ljsrvy3e

ljsrvy3e1#

要等待Ajax响应,最好的方法是从success块中调用该函数。因此,代码将在Ajax响应得到它之后被调用。

  1. Ext.Ajax.request({
  2. url: PORTALURL.EXCEPTION.MAX_VALUE,
  3. success: function(response) {
  4. var maxValue = Ext.decode(response.responseText);
  5. if (grid.getSelectionModel().getSelection().length > maxValue) {
  6. Ext.Msg.alert('Alert!', type + ' count is more than 10');
  7. return;
  8. }
  9. // Call the required function which needs to be executed after ajax response.
  10. CommonUtil.alertConfirm(msg, function() {
  11. .. }
  12. }
  13. });

字符串

展开查看全部
yx2lnoni

yx2lnoni2#

有这样一个属性允许请求变为同步。通过添加该属性:

  1. Ext.Ajax.request({
  2. async: true,
  3. // other properties for the request
  4. });

字符串
更多可以在Stackoverflow对一篇文章here的回答中找到。

相关问题