(function() {
function alertJSON(json) {
alert("json:" + json);
}
function treeInit() {
buildJSONTree(alertJSON);
}
function buildJSONTree(callback) {
var handleSuccess = function(o) {
var json = YAHOO.lang.JSON.parse(o.responseText);
callback(json);
};
var handleFailure = function(o) {
alert("FAILURE");
};
var asyncCallback = {
success : handleSuccess,
failure : handleFailure,
timeout : 5000
};
var send = function(o) {
var sUrl = "http://127.0.0.1:8080/TestMVC/resources/json/category-subject.json";
YAHOO.util.Connect.asyncRequest('GET', sUrl, asyncCallback);
}();
}
YAHOO.util.Event.onDOMReady(treeInit);
})();
And then in my html file I include that script and it executes. I can follow it in the debugger until it executes the asyncRequest, it just returns and neither of my handlers executes.
I made a fiddle and for me it is working. The success callback is called if the resource is available.
http://jsfiddle.net/uZfX5/
In the fiddle the server returns no json and so the json parser crashes but i think that was not the point.