Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS-$HTTP错误请求到Web Api端点_Javascript_Angularjs - Fatal编程技术网

Javascript AngularJS-$HTTP错误请求到Web Api端点

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

问题背景:

我正在学习AngularJS,并尝试使用$HTTP发出我的第一个HTTP请求

问题:

我有一个Web Api端点,目前可以与我拥有的非AngularJS应用程序配合使用

当我尝试使用$http通过Angular调用端点时,IE控制台中出现以下错误:

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);
    }