The AjaxStub class is written using closures and auto instantiates when ajaxstub.js file is fully loaded. The instantiated object is always AjaxStub which is also used to call the constructor of the class-yes after it was instantiated. Douglas Crockford http://www.crockford.com/javascript/private.html is credited for developing this methodology.
var funcList = ['exception', 'logging', 'username',
'getExamples', 'login', 'submit'];
window.onload = function() {
AjaxStub("http://yoururl.com/yourscript.py",
contentType, funcList);
}
In the example above url is coded by the developer and the last two arguments contentType and funcList are pushed to the web page by the Python AjaxStub API.
var loggingCB = function() {
var logging = document.getElementById("logging");
logging.innerHTML += result + "<br />";
logging.scrollTop = 1000000;
}
var someFunction = function() {
...
AjaxStub.log('Results of some process.');
...
}
In the above example first set a variable debug to true then write a callback that does something with your log message so when you use log in your code the message has someplace to go.
It might seem confusing as to why, if you registered your stubs in the Python API, you would need to do it again. Well you don't unless you push JavaScript code up to your page which you may want to delete later. The register method is called in the constructor and through introspection finds the stubs and the callbacks. When the class first gets instantiated it will not find the callbacks which you have just pushed up to your page. You must write and pre-register the stubs, however; because the Python API will at the time the page is requested create and put them in the page. I suppose if you wanted to write the stubs yourself and push them up also this may work, but I have never tried this approach myself.
AjaxStub.register(list);
AjaxStub.unregister(list);
var foo = function() {
AjaxStub.executeStub('foo', 'GET', foo.arguments);
}
The code above is generally auto generated by the Python AjaxStub API.
Carl J. Nobile 2007-08-02