1

I am new to angular and trying to use $resource to send a POST and receive a result.The post goes ok, but rather than a JSON result, I get a char[] of the JSON result.I really will appreciate help

Here is my codes: controller

(function (appTI) {
var TravelController = function ($scope, TravelFactory) {
    var travelParam = {
        Ages: [],
        FromDate: '2017-07-15',
        ToDate: '2017-08-28',
        ResidentCountry: 'NG',
        BookingId: "292928727",
        FromCountry: 'Nigeria',
        ToCountries: ['United States'],
        NoOfTravellers: 2,
        Travellers: [],
        CurrencyCode: "NGN",
        TravelInsurancePrice: "",
        TravelInsuranceRequestId:""
    };

        TravelFactory.save(travelParam, success);
        function success(response) {
            console.log(angular.toJson(response));                
        }

    };
};

TravelController.$inject = ['$scope', 'TravelFactory']; 
appTI.controller('TravelController', TravelController); 
}(angular.module('appTI')));

Now Factory:

(function (appTI) {
var TravelFactory = function ($resource) {
    return $resource('/TravelIns/GetPrice/:verb', { verb: '@id' });
};
TravelFactory.$inject = ['$resource'];
appTI.factory("TravelFactory", TravelFactory);
}(angular.module("appTI")));

Response(comes in char[] instead of json string:

{"data":{"0":"{","1":"\"","2":"I","3":"s","4":"S","5":"u","6":"c","7":"c","8":"e","9":"s","10":"s","11":"f","12":"u","13":"l","14":"\"","15":":","16":"t","17":"r","18":"u","19":"e","20":",","21":"\"","22":"R","23":"e","24":"q","25":"u","26":"e","27":"s","28":"t","29":"I","30":"d","31":"\"","32":":","33":"\"","34":"6","35":"7","36":"4","37":"6","38":"9","39":"f","40":"8","41":"a","42":"-","43":"3","44":"c","45":"a","46":"4","47":"-","48":"4","49":"a","50":"4","51":"f","52":"-","53":"8","54":"b","55":"a","56":"7","57":"-","58":"1","59":"c","60":"c","61":"6","62":"e","63":"e","64":"5","65":"f","66":"0","67":"1","68":"3","69":"8","70":"\"","71":",","72":"\"","73":"C","74":"u","75":"r","76":"r","77":"e","78":"n","79":"c","80":"y","81":"C","82":"o","83":"d","84":"e","85":"\"","86":":","87":"\"","88":"N","89":"G","90":"N","91":"\"","92":",","93":"\"","94":"P","95":"r","96":"e","97":"m","98":"i","99":"u","100":"m","101":"\"","102":":","103":"2","104":"4","105":"3","106":"2","107":"0","108":".","109":"0","110":",","111":"\"","112":"M","113":"e","114":"s","115":"s","116":"a","117":"g","118":"e","119":"\"","120":":","121":"n","122":"u","123":"l","124":"l","125":",","126":"\"","127":"V","128":"e","129":"n","130":"d","131":"o","132":"r","133":"N","134":"a","135":"m","136":"e","137":"\"","138":":","139":"\"","140":"A","141":"x","142":"a","143":"M","144":"a","145":"n","146":"s","147":"a","148":"r","149":"d","150":"\"","151":",","152":"\"","153":"V","154":"e","155":"n","156":"d","157":"o","158":"r","159":"P","160":"r","161":"e","162":"m","163":"i","164":"u","165":"m","166":"\"","167":":","168":"2","169":"4","170":"3","171":"2","172":"0","173":".","174":"0","175":"}"}}
georgeawg
  • 48,608
  • 13
  • 72
  • 95
Caesar
  • 59
  • 1
  • 10
  • 1
    try mentioning `isArray:false`, check this out https://docs.angularjs.org/api/ngResource/service/$resource. this may help – Sibiraj May 10 '17 at 09:23
  • `isArray:false` is the default for the `save` action. That is not the problem. What are you using for the backend? Have you verified it with another method such as Postman, curl, or `$http.post`? – georgeawg May 11 '17 at 00:24

0 Answers0