javascript - Sending Ajax request only once -


When I change the URL of the main browser, I am using the following code to call the function.

  var mainWindow = window.QueryInterface (.comonents.interfaces.nsIInterfaceRequestor) .get interface (Components.interfaces.nsIWebNavigation) .interface (Components.interfaces.nsIDocShellTreeItem) .rootTreeItem .QueryInterface (Components.interfaces .nsIInterfaceRequestor) .get interface (Components.interfaces .nsIDOMWindow); MainWindow.getBrowser () AddEventListener ("DOMContentLoaded", function () {getFromDB ();}, false);  

this sends the request to getFromDB () server

  request = new XMLHttpRequest (); Request.open ("GET", "http://www.mydomain.com/getJSON.php", true); request.  

Everything is working fine, but the problem is that sometimes the request is being sent to the server for infinite numbers. If the browser loads from a page within loacalhost , the request is only sent once.

I load / request per page (URL changes only)

I have used some Boolean checks. But they do not work.

  var check = 0; If (check == 0) {check = 1; GetFromDb (); }  

In the first addEventListener line: 8 help me get it.

You need a global variable for this

  if (window .check == 0 || typeof (window.check) == "undefined") {Window.check = 1; GetFromDb (); }  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -