function ObjectProvider() {
this.url = "ajax/inbounds.php"
this.inBounds = function () {
this.removeMarkers();
var url_string = this.url;
$.getJSON(url_string, function (data) {
for (i = 0; i != data.length; ++i) {
this.createObject(data[i]);
}
});
};
this.createObject = function (_data) {};
this.removeMarkers = function () {};
};
So the line
this.createObject( data[i] );
is having some issues, but
this.removeMarkers();
works fine.
Both functions are defined in the ObjectProvider object.
Have tried adding a function called test() and just doesn’t like anything being called within the JSON callback function.
This is a typical scoping problem; the
thisinside your$.getJSON()callback function is no longer the samethis.To resolve the problem, you have to keep a reference to
thisbefore calling$.getJSON(), e.g.Or, bind the success callback function using
$.proxy: