Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load google visualization api second time

I am facing this issue in my application which contains google chart.

While user starts the application, if the network is not available, I show an alert saying "Network is not available" and send him out of application. This is the code being used:

// 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();
    }
}

But if there is network while user starts the application; the google api is loaded properly for first time. Now suppose the user is still on login page configuring url and suddenly network gets disconnected. At this time even after network gets connected again, the application UI gets freezed. It was due to google visualization API. I need to reload the visualization API as soon as devices gets connected to network again.

I tried calling the same load function in onOnline event listener of Phonegap as shown below:

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

This allows me to proceed to login. But after login, when I click on the button which shows chart, it just shows me a progress dialog saying "Loading". So the Visualization API was not being reloaded properly.

Any idea what I need to do?

like image 742
MysticMagicϡ Avatar asked Aug 03 '26 22:08

MysticMagicϡ


1 Answers

After around a month's searching and trying out, I found that

It is not possible.

No matter, what I do, Google API won't be reloaded after network gets connected again.

So my only option was, to logout from application as soon as network gets disconnected. And make the user login again after network is available.

Still, I would be glad if anyone proves me wrong.

like image 180
MysticMagicϡ Avatar answered Aug 06 '26 15:08

MysticMagicϡ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!