0

I am unable to fetch json data from $http post method in angularjs I had try following code in my controller file

var sectionTypeVM = new Object();
            sectionTypeVM.sessionid = 'Session';
            sectionTypeVM.query = 'where LOB group by Report_Source_Type,Report_Object_Type';
           // alert(JSON.stringify(sectionTypeVM));
            $http({
                method: 'post',
                url: 'http://testserver/search',
                dataType: 'json',
                data: JSON.stringify(sectionTypeVM),
                headers: { 'Content-Type': 'application/json' }
            }).success(function(data, status, headers, config) {
                alert('success');
                alert(data);
                })
            .error(function(data, status, headers, config) {
                alert('error');
                  alert(data+ status + headers + config );
            });

My $http request return error function when called. I am using AngularJS v1.2.16

Thanks Gajanan

5
  • 4
    And what is the error? You're alerting the arguments to the error function. What do they say? You have access to the request and the response via the Net tab of your browser's developer tools. Are they the request and response that you expect? Commented Oct 12, 2015 at 14:50
  • You don't need to stringify the JSON when you add it to the data in your $http. Commented Oct 12, 2015 at 14:51
  • I am getting in error alert status = 0 and headers = function (name) { "use strict"; if (!headersObj) headersObj = parseHeaders(headers); if (name) { return headersObj[lowercase(name)] || null; } return headersObj; }[object Object] Commented Oct 12, 2015 at 15:48
  • When i call $http request and check in fiddler its shows request header is OPTIONS /search HTTP/1.1 instead of POST and I don't see json request getting passed to server Commented Oct 12, 2015 at 15:54
  • I want to add some more details to this question, we work together, we are trying to make this REST API call different from original domain server, so in this case test server maps to domain different the web site. Is this CORS related issue? Is there any settings we need to enable in AngularJS to enable cross domain API invoke? Commented Oct 12, 2015 at 21:31

0

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.