|
From: <ma...@us...> - 2010-11-21 19:37:32
|
Revision: 147
http://openautomation.svn.sourceforge.net/openautomation/?rev=147&view=rev
Author: mayerch
Date: 2010-11-21 19:37:26 +0000 (Sun, 21 Nov 2010)
Log Message:
-----------
Ignore AJAX error calls when we don't need them (i.e. connection isn't needed or finished)
Modified Paths:
--------------
CometVisu/trunk/visu/lib/cometvisu-client.js
CometVisu/trunk/visu/lib/templateengine.js
Modified: CometVisu/trunk/visu/lib/cometvisu-client.js
===================================================================
--- CometVisu/trunk/visu/lib/cometvisu-client.js 2010-11-20 20:25:09 UTC (rev 146)
+++ CometVisu/trunk/visu/lib/cometvisu-client.js 2010-11-21 19:37:26 UTC (rev 147)
@@ -27,6 +27,7 @@
this.pass = ''; // the current password
this.device = ''; // the current device ID
this.running = false; // is the communication running at the moment?
+ this.xhr = false; // the ongoing AJAX request
/**
* This function gets called once the communication is established and session information is available
@@ -41,7 +42,7 @@
// send first request
this.running = true;
- $.ajax( {url:this.urlPrefix + 'r',dataType: 'json',context:this,data:this.buildRequest()+'&t=0', success:this.handleRead ,error:this.handleError/*,complete:this.handleComplete*/ } );
+ this.xhr = $.ajax( {url:this.urlPrefix + 'r',dataType: 'json',context:this,data:this.buildRequest()+'&t=0', success:this.handleRead ,error:this.handleError/*,complete:this.handleComplete*/ } );
};
/**
@@ -53,7 +54,7 @@
{
if( this.running )
{ // retry initial request
- $.ajax( {url:this.urlPrefix + 'r',dataType: 'json',context:this,data:this.buildRequest()+'&t=0', success:this.handleRead ,error:this.handleError/*,complete:this.handleComplete*/ } );
+ this.xhr = $.ajax( {url:this.urlPrefix + 'r',dataType: 'json',context:this,data:this.buildRequest()+'&t=0', success:this.handleRead ,error:this.handleError/*,complete:this.handleComplete*/ } );
}
return;
}
@@ -64,7 +65,7 @@
if( this.running )
{ // keep the requests going
- $.ajax( {url:this.urlPrefix + 'r',dataType: 'json',context:this,data:this.buildRequest()+'&i='+lastIndex, success:this.handleRead ,error:this.handleError/*,complete:this.handleComplete*/ } );
+ this.xhr = $.ajax( {url:this.urlPrefix + 'r',dataType: 'json',context:this,data:this.buildRequest()+'&i='+lastIndex, success:this.handleRead ,error:this.handleError/*,complete:this.handleComplete*/ } );
}
};
@@ -74,7 +75,19 @@
*/
this.handleError=function(xhr,str,excptObj)
{
- alert('Error! "'+str+'"');
+ if( this.running && xhr.readyState != 4 ) // ignore error when connection is irrelevant
+ {
+ var readyState = 'UNKNOWN';
+ switch( xhr.readyState )
+ {
+ case 0: readyState = 'UNINITIALIZED'; break;
+ case 1: readyState = 'LOADING' ; break;
+ case 2: readyState = 'LOADED' ; break;
+ case 3: readyState = 'INTERACTIVE' ; break;
+ case 4: readyState = 'COMPLETED' ; break;
+ }
+ alert('Error! Type: "'+str+'" ExceptionObject: "'+excptObj+'" readyState: '+readyState);
+ }
}
this.handleComplete=function(xhr,str)
{
@@ -124,6 +137,8 @@
this.stop = function()
{
this.running = false;
+ this.xhr.abort();
+ //alert('this.stop');
};
/**
Modified: CometVisu/trunk/visu/lib/templateengine.js
===================================================================
--- CometVisu/trunk/visu/lib/templateengine.js 2010-11-20 20:25:09 UTC (rev 146)
+++ CometVisu/trunk/visu/lib/templateengine.js 2010-11-21 19:37:26 UTC (rev 147)
@@ -114,6 +114,10 @@
}
} );
+$(window).unload(function() {
+ visu.stop();
+});
+
function map( value, element )
{
var map = element.data('mapping');
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|