5

I'm fetching some data from remote server using AngularJS $http. It's working in browser but not in phonegap developer app. But, ajax is working. What could be the problem!!

Here is the code I'm using.

$http({
    url: domain + "modulesinfo/list",
    method: "GET",
    //Added after some research // I'm testing on local server
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
    }
})
.success(function(data){
    $scope.modules = data.response; 
    $scope.$apply();
})
.error(function(){
    navigator.notification.alert("You are damned", function(){

    }, "Not working", "OK");
});

I tried adding header after some research, But that didn't work.

6
  • 2
    It may be a CORS restriction. Can you access a developper console on the device your are testing this ? Commented Mar 31, 2015 at 7:53
  • I'm able to log via adb logcat. Commented Mar 31, 2015 at 8:20
  • And I'm sure that Access-Control-Allow-Origin is already there in header of my PHP file I'm getting response from. Commented Mar 31, 2015 at 8:22
  • you should post your update as an answer to your question, and accept your own answer; otherwise, your question will continue to appear in the "unanswered" category Commented Apr 9, 2015 at 7:04
  • awesomescreenshot.com/image/54885/… Yeah I know that. But, I hope this explains something. :P Commented Apr 9, 2015 at 8:35

1 Answer 1

1
$http.jsonp(domain + "modulesinfo/list?callback=JSON_CALLBACK")
.success(function(data){
    console.log(data);
    $scope.modules = data.response;
})
.error(function(){
    console.log(data);
});

This solved my problem. Hope it help others. Adding the callback=JSON_CALLBACK with the url is working in my case.

Sign up to request clarification or add additional context in comments.

1 Comment

So your endpoint was a jsonp resource instead of a rest endpoint? That would have been useful information to provide in the question.

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.