0

I have Restful API service in asp.net, which provides code for JavaScript to use, i need to use its functions in angular. I am posting code here which has RestAPI function and it includes calls to data and it should return JSON data to calling function i believe. please if anybody familiar with the solution your response will be highly appreciated. Thank-you.

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);
    }
};
1
  • With all due respect - this is not a RESTful API. Commented Sep 6, 2017 at 14:45

1 Answer 1

3

This may help you to solve ASP.NET Web Service In AngularJS Using $HTTP

user $http service for Restful

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;
                });
            });
Sign up to request clarification or add additional context in comments.

1 Comment

it says token is not defined, can you please check it one more time?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.