【问题标题】:Load google visualization api second time第二次加载google可视化api
【发布时间】:2013-11-29 13:00:46
【问题描述】:

我在包含谷歌图表的应用程序中遇到了这个问题。

当用户启动应用程序时,如果网络不可用,我会显示“网络不可用”的警报并让他退出应用程序。这是正在使用的代码:

// In case there is no network
// the google jsapi is not loaded causing the screen to go white and break the application
// Check if google object is not null
if(typeof(google) !== 'undefined')
{
    google.load('visualization', '1.0', {'packages':['corechart']});
}

function ajaxFailure(jqXHR, textStatus, errorThrown)
{
    hideModal();

    // Check for no network connection
    if(navigator.connection.type == 'none' || jqXHR == -1)
    {
        $('#txtUrl').val('');

        navigator.notification.alert('No Network Connection!\n Please connect to a network and try again.', exitApp, 'Attention', 'OK');
    }
}

function exitApp()
{
    //exit app for android client..
    if(/Android/i.test(navigator.userAgent))
    {
        navigator.app.exitApp();
    }
}

但是如果用户启动应用程序时有网络; google api 首次正确加载。现在假设用户仍在登录页面配置 url 并且突然网络断开连接。此时即使重新连接网络,应用程序 UI 也会冻结。这是由于谷歌可视化API。一旦设备再次连接到网络,我需要重新加载可视化 API。

我尝试在Phonegap的onOnline事件监听器中调用相同的加载函数,如下所示:

function onOnline()
{
    if(typeof(google) !== 'undefined')
    {
        google.load('visualization', '1.0', {'packages':['corechart']});
    }
}

这允许我继续登录。但是登录后,当我单击显示图表的按钮时,它只会显示一个进度对话框,上面写着“正在加载”。所以 Visualization API 没有正确重新加载。

知道我需要做什么吗?

【问题讨论】:

    标签: android jquery-mobile cordova google-visualization


    【解决方案1】:

    经过大约一个月的搜索和尝试,我发现

    这是不可能的。

    不管我做什么,重新连接网络后Google API都不会重新加载。

    所以我唯一的选择是,一旦网络断开,就从应用程序中注销。并在网络可用后让用户重新登录。

    不过,如果有人证明我错了,我会很高兴。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-07
      • 2021-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多