Possible Duplicate:
$(this) inside of AJAX success not working
I have the following sample code (JSFiddle to follow)
AdvancedSearch = function() {
this.current = 'test';
}
AdvancedSearch.prototype.InitPage = function() {
var t = this.current;
this.PrePopulate()
}
AdvancedSearch.prototype.UpdateData= function() {
alert(this.current);
}
AdvancedSearch.prototype.PrePopulate = function() {
this.UpdateData();
$.ajax({
url: 'http://fiddle.jshell.net/',
success: function(msg) {
this.UpdateData();
}
});
}
var as = new AdvancedSearch();
as.InitPage();
I have the 'http://fiddle.jshell.net' in there so prevent the Access-Control-Allow-Origin error on their site.
When executing this code, I get the following error:
Uncaught TypeError: Object # has not method 'UpdateData'
If you execute the JSFiddle, you will find that when PrePopulate is called, it runs the this.UpdateData() at the beginning of the function just fine. But as soon as the Ajax call is finished, you get the error.
Any thoughts to why this is happening? Perhaps I'm approaching this in the wrong way. Any insight would help.
Here is my JSFiddle: http://jsfiddle.net/B4NRY/2/