Sending Ajax request only once
I'm using the following code to call a function when the main browser's url changes.

    var mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                         .getInterface(Components.interfaces.nsIWebNavigation)
                         .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
                         .rootTreeItem
                         .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                         .getInterface(Components.interfaces.nsIDOMWindow); 
    
          mainWindow.getBrowser().addEventListener("DOMContentLoaded",function(){ getFromDB();}, false);

This `getFromDB()` sends a request to the server

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

Everything is working fine, but the problem is that the request is being sent to the server for infinite number of times. If the browser is loaded with a page within `loacalhost` then the request is sent only once.

I want to restrict the request to be sent only once per page load/request (or URL change).

I've used some Boolean check. But they ain't work.

    var check=0;
    if(check==0)
    {
    check=1;
    getFromDb();
    }
inside the first `addEventListener` in line:8
Help me to get this.
Sending Ajax request only once
===

I'm using the following code to call a function when the main browser's url changes.

    var mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                         .getInterface(Components.interfaces.nsIWebNavigation)
                         .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
                         .rootTreeItem
                         .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                         .getInterface(Components.interfaces.nsIDOMWindow); 
    
          mainWindow.getBrowser().addEventListener("DOMContentLoaded",function(){ getFromDB();}, false);

This `getFromDB()` sends a request to the server

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

Everything is working fine, but the problem is that the request is being sent to the server for infinite number of times. If the browser is loaded with a page within `loacalhost` then the request is sent only once.

I want to restrict the request to be sent only once per page load/request (or URL change).

I've used some Boolean check. But they ain't work.

    var check=0;
    if(check==0)
    {
    check=1;
    getFromDb();
    }
inside the first `addEventListener` in line:8
Help me to get this.