Async Ajax inside a JS object

I am trying to use the ajax module to fetch data asynchronously and I’m having some difficulty in getting access to object properties inside the callback function. I understand that I need to use ‘closure’ to get the ‘this’ variable to be in scope inside the callback function but my feeble attempts have failed miserably. This is an outline of my code:

function mainFunction() { this.myProperty = new RegExp('some string'); this.myFunction = function() { var params = 'abc=xyz';'myProg', params, function (xmlLoader) { dhtmlxAjax.get('libraries/xslt/xhtml.xsl', function (xslLoader) { if (xmlLoader) { var xhtml = xmlLoader.doXSLTransToString(xslLoader.xmlDoc.responseXML); var regmatch = this.myProperty.exec(xhtml); } }); }); }; }I’d appreciate any suggestions about how I get this.myProperty in scope inside the callback. Two options I have are to use a global instead of an object property or to create the RegExp object inside each callback function but I’d like an elegant solution.

I have the same problem. “this” from inside of the callback function is the XMLHttpRequest object. I cannot set explicitly the scope of the callback function? How can I call any other method that is not global?

Any help is appreciated!!!