Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.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调用Restful api函数_Javascript_Angularjs_Xmlhttprequest - Fatal编程技术网

Javascript 从AngularJs调用Restful api函数

Javascript 从AngularJs调用Restful api函数,javascript,angularjs,xmlhttprequest,Javascript,Angularjs,Xmlhttprequest,我在asp.net中有Restful API服务,它提供了JavaScript使用的代码,我需要在angular中使用它的函数。 我在这里发布的代码具有RestAPI函数,它包括对数据的调用,我相信它应该将JSON数据返回给调用函数。如果有任何人熟悉该解决方案,我们将非常感谢您的回复。 多谢各位 function RestAPI(){ self = this; } RestAPI.prototype = { self: null, urlString: "http://exclu

我在asp.net中有Restful API服务,它提供了JavaScript使用的代码,我需要在angular中使用它的函数。 我在这里发布的代码具有RestAPI函数,它包括对数据的调用,我相信它应该将JSON数据返回给调用函数。如果有任何人熟悉该解决方案,我们将非常感谢您的回复。 多谢各位

function RestAPI(){ self = this; }
RestAPI.prototype = {
    self: null,
    urlString: "http://exclusiveautosales.azurewebsites.net/ExclusiveAutoSales_Handler.ashx",
    GetFiltersMain:function(successFunction,failFunction,token) {
        var data = { 'interface': 'RestAPI', 'method': 'GetFiltersMain', 'parameters': {}, 'token': token };
        var jsonData = dojo.toJson(data);
        var xhrArgs = {
            url: self.urlString,
            handleAs: 'json',
            postData: jsonData,
            load: successFunction,
            error: failFunction };
        var deferred = dojo.xhrPost(xhrArgs);
    },
    GetMakeModelPrice:function(make_id,model_id,min_price,max_price,successFunction,failFunction,token) {
        var data = { 'interface': 'RestAPI', 'method': 'GetMakeModelPrice', 'parameters': {'make_id':make_id,'model_id':model_id,'min_price':min_price,'max_price':max_price}, 'token': token };

        var jsonData = dojo.toJson(data);
        var xhrArgs = {
            url: self.urlString,
            handleAs: 'json',
            postData: jsonData,
            load: successFunction,
            error: failFunction };
        var deferred = dojo.xhrPost(xhrArgs);
    },
    GetSearchResult:function(search_q,make_id,model_id,year_id,engine_id,color_id,body_id,transmission_id,fueltype_id,subfeature_id,minPrice,maxPrice,successFunction,failFunction,token) {
        var data = { 'interface': 'RestAPI', 'method': 'GetSearchResult', 'parameters': {'search_q':search_q,'make_id':make_id,'model_id':model_id,'year_id':year_id,'engine_id':engine_id,'color_id':color_id,'body_id':body_id,'transmission_id':transmission_id,'fueltype_id':fueltype_id,'subfeature_id':subfeature_id,'minPrice':minPrice,'maxPrice':maxPrice}, 'token': token };

        var jsonData = dojo.toJson(data);
        var xhrArgs = {
            url: self.urlString,
            handleAs: 'json',
            postData: jsonData,
            load: successFunction,
            error: failFunction };
        var deferred = dojo.xhrPost(xhrArgs);
    }
};

这可能会帮助您解决问题

用于Restful的用户
$http
服务

var app = angular.module('myApp', []);
       app .controller('RestAPI',function($scope, $http) {                    
                $http({
                    method : "GET",
                    url : "http://exclusiveautosales.azurewebsites.net/ExclusiveAutoSales_Handler.ashx",
                    data :{ 'interface': 'RestAPI', 'method': 'GetFiltersMain', 'parameters': {}, 'token': token }
                }).then(function mySucces(response) {
                    $scope.jsonData = response.data;
                }, function myError(response) {
                    $scope.jsonData = response;
                });
            });

这可能会帮助您解决问题

用于Restful的用户
$http
服务

var app = angular.module('myApp', []);
       app .controller('RestAPI',function($scope, $http) {                    
                $http({
                    method : "GET",
                    url : "http://exclusiveautosales.azurewebsites.net/ExclusiveAutoSales_Handler.ashx",
                    data :{ 'interface': 'RestAPI', 'method': 'GetFiltersMain', 'parameters': {}, 'token': token }
                }).then(function mySucces(response) {
                    $scope.jsonData = response.data;
                }, function myError(response) {
                    $scope.jsonData = response;
                });
            });

它说令牌没有定义,你能再检查一遍吗?它说令牌没有定义,你能再检查一遍吗?恕我直言-这不是RESTful API。恕我直言-这不是RESTful API。