The toc widget is acting strange. it is not loading. sometimes after multiple refresh, it loads fine.

here is the error message I get:

here is my code
//define Proxy
esriConfig.defaults.io.proxyUrl = "proxy.ashx";
esriConfig.defaults.io.alwaysUseProxy = false;
//============================
map.on("load", function (evt) {
mapReady();
getLayers();
});
//LEGEND CHECKBOX
function getLayers() {
map.on("layer-add-result", function (evt) {
// console.log(evt);
try {
toc = new TOC({
map: map,
layerInfos: [{
layer: layerName,
title: "Layers",
collapsed: false,
slider: true
}]
}, 'legendDiv');
toc.startup();
}
catch (ex) {
// console(ex.toString());
}
})
}I am not sure why the toc is not loading correctly. Any ideas?
The error message is :
message: "Unable to load http://www.arcgis.com/sharing/tools/legend?soapUrl=http