Beneath are my AJAX code snippet.
In rescanNetwork(), there are two calls of newAJAXCommand(). The primary one “newAJAXCommand(‘scan.cgi?scan=1’);” The second is “setTimeout(“newAJAXCommand(‘standing.xml’, updateStatus, false)”, 50)”
The content material of scan.cgi is form of “Success! scan”. My questions are:
- Per my understanding, scan.cgi have to be a CGI script written in Perl, Python, or one other scripting language. “Success! scan” doesn’t seem like a script of any language. How come? What does it imply?
- What is that this name “newAJAXCommand(‘standing.xml’, updateStatus, false)” for? the place ‘updateStatus’ is a JavaScript operate as under.
- In “newAJAXCommand”, as soon as “newAjax.ajaxReq.ship(knowledge);” is executed, the server facet related operate have to be known as, however I discovered no operate was known as. How can I discover the lacking place?
// Initiates a brand new AJAX command
// url: the url to entry
// container: the doc ID to fill, or a operate to name with response XML (non-compulsory)
// repeat: true to repeat this name indefinitely (non-compulsory)
// knowledge: an URL encoded string to be submitted as POST knowledge (non-compulsory)
operate newAJAXCommand(url, container, repeat, knowledge)
// Arrange our object
var newAjax = new Object();
var theTimer = new Date();
newAjax.url = url;
newAjax.container = container;
newAjax.repeat = repeat;
newAjax.ajaxReq = null;
// Create and ship the request
if (window.XMLHttpRequest)
newAjax.ajaxReq = new XMLHttpRequest();
newAjax.ajaxReq.open((knowledge==null)?"GET":"POST", newAjax.url, true);
newAjax.ajaxReq.ship(knowledge);
// If we're utilizing IE6 model (perhaps 5.5 suitable too)
else if (window.ActiveXObject)
newAjax.ajaxReq = new ActiveXObject("Microsoft.XMLHTTP");
if (newAjax.ajaxReq)
newAjax.ajaxReq.open((knowledge==null)?"GET":"POST", newAjax.url, true);
newAjax.ajaxReq.ship(knowledge);
newAjax.lastCalled = theTimer.getTime();
// Retailer in our array
ajaxList.push(newAjax);
.......
operate updateStatus(xmlData)
......
.....
operate rescanNetwork()
scanDots = 0;
printButtonName();
doc.getElementById("rescan").disabled = true;
// Generate a request to {hardware} to subject a rescan
newAJAXCommand('scan.cgi?scan=1');
// Delete previous desk, substitute with new desk after scan is completed
deleteScanTable();
currBss = 0; // Reset the present bss pointer
setTimeout("newAJAXCommand('standing.xml', updateStatus, false)", 50);
scan.cgi have to be one thing that an internet browser, pulling a typical HTTP request for the URL (Common Useful resource Locator) object referenced by ‘scan.cgi?scan=1’, acknowledges and returns one thing from. It’s very open to interpretation; usually, a CGI script would, certainly, be some type of script in a language to be run by the server’s processing features. But it surely doesnt should be. It may simply be some textual content that will get returned.
Properly, setTimeout tells Javascript “wait this many milliseconds (50), after which run this line of code.” (you may additionally put a operate there, and so on).
newAJAXCommand(‘standing.xml’, updateStatus, false) says “Go get me standing.xml, set the container to the operate reference for updateStatus, and the repeat to false.” What do container and repeat do? Dunno. You havent present n us something that references these properties of that object.
ship
on this case is a operate of the item (both the XMLHttpRequest object or the ActiveXObject relying on how previous your browser is…). It sends the request to truly go and do the speaking with the server. It’s a predefined operate of that object class, as is open
.