Some questions about my JavaScript codes

Below are my AJAX code snippet.
In rescanNetwork(), there are two calls of newAJAXCommand(). The first one “newAJAXCommand(‘scan.cgi?scan=1’);” The second one is “setTimeout(“newAJAXCommand(‘status.xml’, updateStatus, false)”, 50)”
The content of scan.cgi is kind of “Success! scan”. My questions are:

  1. Per my understanding, scan.cgi must be a CGI script written in Perl, Python, or another scripting language. “Success! scan” doesn’t look like a script of any language. How come? What does it mean?
  2. What is this call “newAJAXCommand(‘status.xml’, updateStatus, false)” for? where ‘updateStatus’ is a JavaScript function as below.
  3. In “newAJAXCommand”, once “newAjax.ajaxReq.send(data);” is executed, the server side associated function must be called, but I found no function was called. How can I find the missing place?
// Initiates a new AJAX command
//  url: the url to access
//  container: the document ID to fill, or a function to call with response XML (optional)
//  repeat: true to repeat this call indefinitely (optional)
//  data: an URL encoded string to be submitted as POST data (optional)
function newAJAXCommand(url, container, repeat, data)
    // Set up our object
    var newAjax = new Object();
    var theTimer = new Date();
    newAjax.url = url;
    newAjax.container = container;
    newAjax.repeat = repeat;
    newAjax.ajaxReq = null;

    // Create and send the request
    if (window.XMLHttpRequest) {
        newAjax.ajaxReq = new XMLHttpRequest();"GET":"POST", newAjax.url, true);
    // If we're using IE6 style (maybe 5.5 compatible too)
    } else if (window.ActiveXObject) {
        newAjax.ajaxReq = new ActiveXObject("Microsoft.XMLHTTP");
        if (newAjax.ajaxReq) {
  "GET":"POST", newAjax.url, true);

    newAjax.lastCalled = theTimer.getTime();

    // Store in our array

function updateStatus(xmlData)

function rescanNetwork()
    scanDots = 0;
    document.getElementById("rescan").disabled = true;

    // Generate a request to hardware to issue a rescan

    // Delete old table, replace with new table after scan is finished

    currBss = 0; // Reset the current bss pointer

    setTimeout("newAJAXCommand('status.xml', updateStatus, false)", 50);

scan.cgi must be something that a web browser, pulling a standard HTTP request for the URL (Universal Resource Locator) object referenced by ‘scan.cgi?scan=1’, recognizes and returns something from. It’s very open to interpretation; normally, a CGI script would, indeed, be some form of script in a language to be run by the server’s processing functions. But it doesnt have to be. It could just be some text that gets returned.

Well, setTimeout tells Javascript “wait this many milliseconds (50), and then run this line of code.” (you could also put a function there, etc).
newAJAXCommand(‘status.xml’, updateStatus, false) says “Go get me status.xml, set the container to the function reference for updateStatus, and the repeat to false.” What do container and repeat do? Dunno. You havent show n us anything that references those properties of that object.

send in this case is a function of the object (either the XMLHttpRequest object or the ActiveXObject depending on how old your browser is…). It sends the request to actually go and do the communicating with the server. It’s a predefined function of that object class, as is open.

“This topic will close 3 months after the last reply.”? How come? My issue is still not figured out but it will be kicked out? Any mistake I made?

All threads on this board are set to auto-close after 3 months of no activity. It’s not kicking you out, it’s just closing conversations that are no longer active, to prevent people from coming back a year later and resurrecting a dead thread.

Have you heard of the AppRefactoring service? It helps with the analysis of the code and, if necessary, helps to make it unique.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.