Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

it's my first app with Angular.js and I've searched so hardly but I can't find a solution:

I've got a search form that makes a request to a web server which retrieves a JSON object; the problem is that this request fails and the error function begins.

Here my code:

$scope.queryUser = {};

    $scope.url = "http://xxxx:8080/MyApp/search.do?index=central&query=";

    $scope.search = function(query) {

         $scope.queryUser= angular.copy(query);

        // Create the http post request
        // the data holds the keywords
        // The request is a JSON request.
        $http.post($scope.url +  $scope.queryUser.value).
        success(function(data, status) {
            $scope.status = status;
            $scope.data = JSON.stringify(data);
            $scope.result = data; // Show result from server in our <pre></pre> element
            console.log(data);
        })
        .
        error(function(data, status) {
            $scope.data = data || "Request failed";
            $scope.status = status;   
            console.log($scope.data);
        });

and this is a sample response:

{"Workstation, Laptop@Workstation$$Laptop":[{"values":{"instanceid":"OI-4A35F9C31E114FBCB5B7668FC5E1FFB4","classid":"COMPUTERSYSTEM"},"index":"distributed"},{"values":{"instanceid":"OI-6A03793A658E45EE90E589D82B0D0962","classid":"COMPUTERSYSTEM"},"index":"distributed"}]}

Any suggestions?

Thanks in advance

share|improve this question
    
Instead of $scope.data = JSON.stringify(data); try this: $scope.data = data; –  artur grzesiak Dec 11 '13 at 21:07
    
if error is triggered, start by finding out status. Also easy to inspect full request in network tab of browser console. Grab response body and paste in jsonlint.com to make sure it is valid –  charlietfl Dec 11 '13 at 21:17
    
The JSON is valid (I use it for another goal). And the code doesn't work neither with $scope.data = data –  sickk Dec 11 '13 at 22:07
    
what error did you get? –  zsong Dec 11 '13 at 23:14
    
As I said, the error function begins with a status 200. The JSON is correct so I don't know how go on –  sickk Dec 12 '13 at 8:24

1 Answer 1

I understood the problem: this is a problem of domain. Making the request calling the same webservlet it works...calling an external server it doesn't work.

DOH! I'm sorry for the question

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.