Javascript AngularJS-$HTTP错误请求到Web Api端点
问题背景: 我正在学习AngularJS,并尝试使用$HTTP发出我的第一个HTTP请求 问题: 我有一个Web Api端点,目前可以与我拥有的非AngularJS应用程序配合使用 当我尝试使用$http通过Angular调用端点时,IE控制台中出现以下错误:Javascript AngularJS-$HTTP错误请求到Web Api端点,javascript,angularjs,Javascript,Angularjs,问题背景: 我正在学习AngularJS,并尝试使用$HTTP发出我的第一个HTTP请求 问题: 我有一个Web Api端点,目前可以与我拥有的非AngularJS应用程序配合使用 当我尝试使用$http通过Angular调用端点时,IE控制台中出现以下错误: SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied. localhost:55315 TypeError: Function expected
SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied.
localhost:55315
TypeError: Function expected
at Anonymous function (http://localhost:55315/Modules/Main.js:105:17)
at Anonymous function (http://localhost:55315/Scripts/angular.min.js:95:194)
at Anonymous function (http://localhost:55315/Scripts/angular.min.js:128:295)
at m.prototype.$eval (http://localhost:55315/Scripts/angular.min.js:142:456)
at m.prototype.$digest (http://localhost:55315/Scripts/angular.min.js:140:39)
at m.prototype.$apply (http://localhost:55315/Scripts/angular.min.js:143:247)
at g (http://localhost:55315/Scripts/angular.min.js:95:442)
at x (http://localhost:55315/Scripts/angular.min.js:100:50)
at e (http://localhost:55315/Scripts/angular.min.js:101:129)
代码:
AngularJS:
Web Api端点:
您使用的是
GET
方法,因此应该使用params
代替数据。另外,您在加载搜索列表
定义之后缺少一个结束}
你可以做一个返回{}
代替var self={}
您使用的是GET
方法,因此应该使用params
代替数据。另外,您在加载搜索列表
定义之后缺少一个结束}
你可以做一个返回{}代码>代替var self={}
app.service('SearchService', function (Search, $http) {
var self = {
searchList: [],
loadSearchList: function () {
$http({
method: 'GET',
url: 'http://thisistheurl.azurewebsites.net/api/ShoppingComparison/GetComparisons',
data : {
itemtosearch: 'rolex',
itemIndex: 'watches',
countryCode: 'UK',
maxPrice: '50000',
minPrice: '0',
highToLow: true,
lowToHigh: false,
amazonEbay: true,
amazonOnly: false,
ebayOnly: false
},
headers: {
'Content-Type':'text/plain; charset=UTF-8',
'Access-Control-Allow-Origin': 'http://localhost:55315/',
'Access-Control-Allow-Methods': 'POST, GET, OPTIONS, PUT, DELETE'}
}).success(function (data, status, headers, config) {
console.log("Passed"+ data + " " + status);
}).error(function (data, status, headers, config) {
console.log("Failed" + data + " " + status);
});
return self;
});
[EnableCors(origins: "*", headers: "*", methods: "*")]
public ViewItemModel GetComparisons(string itemToSearch, string itemIndex, string countryCode,
string maxPrice, string minPrice, bool highToLow, bool lowToHigh, bool amazonEbay,
bool amazonOnly, bool ebayOnly)
{
return _callAndSearchApis.SearchApis(itemToSearch, itemIndex, countryCode,
maxPrice, minPrice, highToLow, lowToHigh, amazonEbay, amazonOnly, ebayOnly);
}