What's new
HTML Forums | An HTML and CSS Coding Community

Welcome to HTMLForums; home of web development discussion! Please sign in or register your free account to get involved. Once registered you will be able to connect with other members, send and receive private messages, reply to topics and create your very own. Our registration process is hassle-free and takes no time at all!

How come the client side clicking can't cause a function in web server side being called?

Stan Huang

New member
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?
JavaScript:
// 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();
        newAjax.ajaxReq.open((data==null)?"GET":"POST", newAjax.url, true);
        newAjax.ajaxReq.send(data);
    // If we're using IE6 style (maybe 5.5 compatible too)
    } else if (window.ActiveXObject) {
        newAjax.ajaxReq = new ActiveXObject("Microsoft.XMLHTTP");
        if (newAjax.ajaxReq) {
            newAjax.ajaxReq.open((data==null)?"GET":"POST", newAjax.url, true);
            newAjax.ajaxReq.send(data);
        }
    }

    newAjax.lastCalled = theTimer.getTime();

    // Store in our array
    ajaxList.push(newAjax);
}

.......
function updateStatus(xmlData)
{
    ......
}
.....

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

    // Generate a request to hardware to issue a rescan
    newAJAXCommand('scan.cgi?scan=1');

    // Delete old table, replace with new table after scan is finished
    deleteScanTable();

    currBss = 0; // Reset the current bss pointer

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