0
I’m developing an application here, and I use a JSON object for popular, but when I use $.getJSON()
Chrome gives the following error:
Xmlhttprequest cannot load file://C:/Users/Jeancarlos/Documents/Github/Networkdiagram/Application/Object.json. Cross origin requests are only supported for Protocol schemes: http, data, Chrome, Chrome-Extension, https, Chrome-Extension-Resource.
Javascript
$(function() {
// This function get error XMLHtmlRequest, because this not supported protocol LOCAL.
$.getJSON('Object.json', function(data) {
console.log('success');
var table = '';
$.each(data.activies, function(key, val) {
table += '<table>';
table += '<tbody>';
table += '<tr><td>' + val.EarlyStart + '</td><td>' + val.Duration + '</td><td>' + val.EarlyFinish + '</td></tr>';
table += '<tr><td colspan="3">' + val.ActivityName + '</td></tr>';
table += '<tr><td>' + val.LateStart + '</td><td>' + val.TotalFloat + '</td><td>' + val.LateFinish + '</td></tr>';
table += '</tbody>';
table += '</table>';
});
$("#content").append(table);
}).error(function() {
console.log('error');
});
});
JSON object.
{"activies" = [{
"EarlyStart": "1",
"Duration": "10",
"EarlyFinish": "2",
"ActivityName": "Activity 1",
"LateStart": "4",
"TotalFloat": "4",
"LateFinish": "5"
}]}
I understand the problem, that this error is a "half security" that Chrome uses, but I need to modify this code to not give more this problem.
You cannot upload anything from the file system and have no way around, in any browser. To make it work, use a web server, have several alternatives on the web, on Node, Python or using Webmatrix. Then you will be loading from the server itself and will not have this problem.
– sergiogarciadev