/    Sign up×
Community /Pin to ProfileBookmark

Help me understand such AJAX code snippet

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();
    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);
    }
    “`

    to post a comment
    JavaScript

    5 Comments(s)

    Copy linkTweet thisAlerts:
    @SempervivumNov 25.2022 — @StanHuang#1648689 Single backticks (probably created by the button `&lt;/&gt;</C>) won't work reliably when posting code. You better use code tags: <C>your code here` or triple backticks. I edited your posting accordingly.
    Copy linkTweet thisAlerts:
    @SempervivumNov 25.2022 — @StanHuang#1648689 Regarding 1.: "Success! scan" ist not the the script. Instead it is the **output** the script is creating.
    Copy linkTweet thisAlerts:
    @StanHuangauthorNov 25.2022 — @Sempervivum#1648695 Since "Success! scan" is not the script, but the output, how come is it in scan.cgi? What script does this call "newAJAXCommand('scan.cgi?scan=1')" really execute to get such output "Success! scan"?
    Copy linkTweet thisAlerts:
    @SempervivumNov 25.2022 — Unfortunately I don't have a clue regarding cgi scripts, however in order to clarify what's going on this is a very basic script in PHP creating the same output:
    ``<i>
    </i>&lt;_?php_&gt;
    echo "Success! scan";
    &lt;_?_&gt;<i>
    </i>
    `</CODE>
    (Note that I had to modify the php tags as the forum software doesn't accept then).<br/>
    When executing this script, the output is "Success! scan".

    In general your script is outdated and incomplete:
    <LIST type="decimal"><LI>1. No need to use ActiveXObject these days, note the remark: "// If we're using IE6 style (maybe 5.5 compatible too)".</LI>
    <LI>2. The additional parameters container, repeat, data are defined but never used in the function.</LI>
    <LI>3. IMO the newer <C>
    fetch</C> is easier to handle than <C>XMLHttpRequest`.
    Copy linkTweet thisAlerts:
    @StanHuangauthorNov 26.2022 — @Sempervivum#1648699 Do you mean I could insert the short PHP script in my server codes? Where to insert? And how will it help me to figure out what my problem is?
    ×

    Success!

    Help @StanHuang spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.23,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...