hi.
I'm creating a Windows form project to collect data from a database and present it as charts in a html file.
After collecting all the data i want, i update an existing json file with those values so i can read and use them to create the charts. My problem is when i try to access the json file from the javascript i get this error
Quote:
xmlhttprequest cannot load file (path of the file) cross origin requests are only supported for http
I'm also using angularjs.
This is how i have my code:
data.json
{
"children":[
{"data": "val1" },
{"data": "val2" },
{"data": "val3" },
{"data": "val4" },
{"data": "val5" }
]
}
Service.js
var jsonService = angular.module('jsonService', ['ngResource']);
jsonService.factory('JsonService', function ($resource) {
return $resource('C:/Users/Lopez/Documents/Visual Studio 2010/Projects/Dashboard/SMO/html/data.json');
});
app.js
var app = angular.module('angularjs-starter', ['jsonService']);
app.controller('MainCtrl', function ($scope, JsonService) {
JsonService.get(function (data) {
$scope.name = data.name;
$scope.children = data.children;
});
});
index.htm
<!DOCTYPE html>
<html ng-app="angularjs-starter">
<head lang="en">
<meta charset="utf-8">
<title>Custom Plunker</title>
<script src="../Scripts/angular.js" type="text/javascript"></script>
<script src="../Scripts/angular-resource.min.js" type="text/javascript"></script>
<script src="../javascript/service.js" type="text/javascript"></script>
<script src="../javascript/app.js" type="text/javascript"></script>
</head>
<body ng-controller="MainCtrl">
<h2>children</h2>
<div ng-repeat="child in children">
{{child.data}}
</div>
</body>
</html>
EDIT:
I've been told to use a WCF WebService to avoid that error message and access the data. I have search the web and read tutorials but i don't understand how can i make a service to do waht the message says it cannot do.
Can you give me any hints?
thk