Hi.
I have a problem which I cant seem to solve and I’ve tried lots of things.
I have a page where it shows "Online Status" to a user.
So if the app is online, it shows "Online".
Checking for internet connectivity status is not instant function, so I
decided to use AJAX to populate the div, so loading of this page does not
block. It’s working as expected, BUT while this “isOnline()” function
doing its thing, I cant go anywhere on my page. If I click on any other link,
it just sits there until "isOnline()" internet checking function completes
its run. To be exact, I’m doing the following:
In my view.php:
<script type="text/javascript">
/*<![CDATA[*/
jQuery(window).load(function() {
jQuery.ajax({
url: '/overview/internetcheck',
type: "POST",
success: function() {
jQuery('#internet_status').html('ONLINE');
}
});
});
/*]]>*/
</script>
<div id="overview_block_1" style="width:485px;">
<?php
$dataProvider = new CArrayDataProvider(
array(
0 => array(
'id' => 0,
"heading" => "Internet Status:",
"value" => '<div id="internet_status"><img src="/images/ajax-loader.gif"></div>',
),
)
);
$this->widget('zii.widgets.grid.CGridView', array(
'enablePagination' => false,
'summaryText' => "",
'id' => 'overview-block-1-grid',
'dataProvider' => $dataProvider,
'template' => "{items}",
'columns'=>array(
array(
'name' => 'heading',
'header' => Yii::app()->params['appName']. ' Info',
'htmlOptions' => array('width'=>'35%', 'style'=>'text-align:right;padding-right:10px;'),
),
array(
'class' => 'MyOverviewCDataColumn',
'name' => 'value',
'header' => "",
'htmlOptions' => array('width'=>'65%', 'style'=>'text-align:left;padding-left:10px;'),
),
),
));
?>
</div>
In my overview/controller file:
public function isOnline($host = 'devatron.com', $port = 80, $timeout = 10) {
$errno = 0;
$errstr = '';
if ($sock = @fsockopen($host, $port, $errno, $errstr, 10)) {
@fclose($sock);
return TRUE;
}
else {
return FALSE;
}
}
public function actionInternetcheck()
{
if ($this->isOnline()) {
header('Content-Type: application/json; charset="UTF-8"');
echo CJSON::encode(array('result'=>'online'));
}
else {
header('Content-Type: application/json; charset="UTF-8"');
echo CJSON::encode(array('result'=>'offline'));
}
Yii::app()->end();
}
This works as I want it (internet_status div’s spinner gets replaced with word “ONLINE”), except I cant click on any other link in my app until isOnline() completes.
Is there any way to stop this "blocking" behavior?
Tried everything I could, nothing works.
Please help.