0

i have implemented a simple Webmethod in c# that returns a JSON string, in this way:

    [WebMethod]
    public string HelloWorld()
    {
        string retStr = "Hello World";
        string jsonStr = JsonConvert.SerializeObject(retStr);
        return jsonStr;
    }

This method is called by an angularjs function:

angular.module('IndexApp', [])
.controller('IndexController', function ($scope, $element, $http) {
    $scope.retData = {};
    $scope.retData.getResult = function (item, event) {
        $http.get('/WebMethods/HTTP_GET.asmx/HelloWorld', { data: {} })
            .then(function (data ̶,̶ ̶s̶t̶a̶t̶u̶s̶,̶ ̶h̶e̶a̶d̶e̶r̶s̶,̶ ̶c̶o̶n̶f̶i̶g̶ ) {
                $scope.retData.result = data.data.d;
            }),
            function errorCallback(response) { }
    }
}).config(function ($httpProvider) {
    $httpProvider.defaults.headers.post = {};
    $httpProvider.defaults.headers.post["Content-Type"] = "application/json; charset=utf-8";  

});

The problem is that on client side functions, in data.data variable, i retrive an XML instead of a json string. How can i do to let return a JSON instead of XML? Thanks in advance for help.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
pasluc74669
  • 1,680
  • 2
  • 25
  • 53

0 Answers0