0
我有一個名爲DemoAPI的文件夾。從腳本標記中的另一個文件夾內加載文件
在DemoAPI ---> app.html
在DemoAPI - >客戶端\ PUBLIC \ core.js
我想包括core.js
在app.html
腳本標籤。
這樣的:
<script type="text/javascript" src="Client/public/core.js"></script>
core.js looks like this:
angular.module('Todo', [])
.controller('mainController', function($scope, $http)
{
$scope.formData = {};
// get all and show them
$http.get('/musicians')
.success(function(data) {
$scope.todos = data;
console.log(data);
})
.error(function(data) {
console.log('Error: ' + data);
});
//get with an id
$scope.getOneTodo = function() {
$http.get('/musicians' + id)
.success(function(data) {
$scope.todos = data;
console.log(data);
})
.error(function(data) {
console.log('Error: ' + data);
});
};
// send the text to the node API
$scope.createTodo = function() {
$http.post('/musicians', $scope.formData)
.success(function(data) {
$scope.formData = {}; // clear the form
$scope.todos = data;
console.log(data);
})
.error(function(data) {
console.log('Error: ' + data);
});
};
// delete
$scope.deleteTodo = function(id) {
$http.delete('/musicians' + id)
.success(function(data) {
$scope.todos = data;
console.log(data);
})
.error(function(data) {
console.log('Error: ' + data);
});
};
/*
$scope.updateTodo = function(id) {
$http.delete('/musicians' + id)
.success(function(data) {
$scope.todos = data;
console.log(data);
})
.error(function(data) {
console.log('Error: ' + data);
});
};*/
});
但我得到一個錯誤,指出:
XMLHttpRequest cannot load file:///C:/musicians. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
它試圖從那裏爲我的意思是URL目錄中獲取/音樂家。 我該如何解決這個問題?
這是由腳本嘗試執行的操作引起的錯誤,而不是由於無法加載腳本導致的。如果您從本地文件系統加載腳本並且不使用node.js來提供腳本,那麼這也是一個錯誤。 – Quentin
@昆汀丁:你說得對。請參閱更新的問題/ –
錯誤消息應該是解釋性的。你需要一個網絡服務器。 – Quentin