1

My web app is using angularjs with spring mvc. When hosted in localhost the http get works fine in all browsers. But once hosted in a diferent server the http get returns the html of main tenplate page as result instead json.This wrong happen only chrome. No erros show in browser console. Someone can help me.

app.config(['$httpProvider', function($httpProvider) {
        $httpProvider.defaults.useXDomain = true;
        delete $httpProvider.defaults.headers.common['X-Requested-With'];
}]);

angular.module('myModule').factory('myService', function($http, $q, CONTEXT_APP) {
    return {

        getPromiseFunction: function(id) {
            var deferred = $q.defer();
            $http.get(CONTEXT_APP + '/mvc/id/' + id).success(function(result){
                deferred.resolve(result);
            });
            return deferred.promise;
        }
    };
});

angular.module('myControllerModule').controller('SecondController', function($scope, $routeParams, myService) {


    var promise = myService.getPromiseFunction($routeParams.id);
    promise then(function(result) {
       $scope.result = result;
    });
});
2
  • It sounds like there is a problem with your server setup. Have you used a network sniffer to watch the packets and compare differences in packets between your localhost setup vs the different server setup? Commented Apr 20, 2014 at 20:11
  • If you don't explicitly state the desired format when making the request, the server "guesses" based on the requesting program. Likely the server doesn't have a default "guess" for Chrome. You need to explicitly state in your request what format you want. (Unfortunately, I can't give you chapter and verse on what to do -- I just know the problem exists.) Commented Apr 20, 2014 at 20:11

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.