But unless i am mistaken this code wouldn't work:
3rdPartyObject.getCustomValue = function {
var json = $.ajax({
type: 'GET',
url: 'whatever',
dataType: 'json',
success: function() { },
data: {},
async: false
});
return json;
}
As $.ajax returns the XHR object not the parsed json object.
You would need to do something more like:
var jsonLoader = function(url){
this.url = url;
this.rawData = {};
this.getRawData();
};
jsonLoader.prototype.getRawData = function(){
var json = $.ajax({
type: 'GET',
url: this.url,
dataType: 'json',
success: this.getRawData(this),
data: {},
async: false
});
};
jsonLoader.prototype. getRawData = function(self){
return function(json){self.rawData = json;};
};
var loadMe = new jsonLoader("Data.json");
loadMe.rawData //has the parsed json object
In fact there is probably a much neater way of achieving the same
answered 2009-07-07T14:29:34.483