【发布时间】: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