blockUI vs ajax,async选项为false [英] blockUI vs ajax with async option to false

查看:130
本文介绍了blockUI vs ajax,async选项为false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要调用一个返回ajax调用内容的javascript函数。

I need to call a javascript function which returns the content of an ajax call.

为了实现这个结果,我在ajax调用中将async选项设置为false。

In order to achieve this result I set async option to false in ajax call.


function ajaxQuery(){
    var content;
    $.ajax({
        url: "blabla.html,
        async: false,
        success: function(data){
            content =   data
        }
    });
    return content;
}

不幸的是,将async选项设置为false make blockUI无法正常工作。
在查询到服务器期间,浏览器被冻结而没有消息。

Unfortunately, setting async option to false make blockUI not working properly. During the query to the server, the browser is frozen with no message.

如果我将async选项设置为true,则blockUI来到工作正常,但我的javascript函数返回值undefined,可能是因为ajax查询没有完成。

If I set async option to true the blockUI comes to work properly but my javascript function return the value undefined, probably because the ajax query is not finished.

如何在javascript函数中解决此问题以获取ajax的内容打电话让blockUI工作?

How to solve this problem in javascript function to get the content of the ajax call making blockUI working?

谢谢,

Antonio

推荐答案

你不能。

同步AJAX调用将完全冻结浏览器,应该不惜一切代价避免;那里没有办法解决这个问题。

Synchronous AJAX calls will completely freeze the browser and should be avoided at all costs; there is no way around that.

相反,你应该这样做d使用回调传递值,与 $ .ajax 相同。

Instead, you should pass the value using a callback, the same way $.ajax does.

这篇关于blockUI vs ajax,async选项为false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆