Ajax启动事件从Controller返回后触发

时间:2015-04-09 16:07:49

标签: javascript jquery ajax

我正在尝试在我的网页执行ProgressBar请求时显示ajax

我正在动态创建dialog,其中包含image,我想在ajaxStart事件中显示它。问题是,当我进行ajax来电时,ajax会在controller返回后开始点击。

$(document).on('ajaxStart',function(){
    alert('x');
    $.OpenLoading(); //method which is creating the dialog and image
});

在这种情况下,立即调用alert。 但是没有创建对话框

但是如果像这样编写相同的代码

$(document).on('ajaxStart',function(){
    console.log('x');
    $.OpenLoading(); //method which is creating the dialog and image
});

然后在从x操作返回后,在控制台controller中打印,但仍未创建对话框。如果我只是在控制台中运行$.OpenLoading(),那么它可以正常工作。

请让我知道我在哪里做错了?

2 个答案:

答案 0 :(得分:0)

alert()停止与浏览器的所有交互,直到消息被解除,即按ok按钮。 而console.log()只是将消息打印到控制台。

答案 1 :(得分:0)

尝试将您的javascript更改为以下内容:

$(document).ajaxStart(function(){
    console.log('x');
    $.OpenLoading(); //method which is creating the dialog and image
});

.ajaxStart只是.on的缩写形式(“ajaxStart”虽然我觉得它在某些情况下效果更好。

相关问题