Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON fetching data using $http is not working in phonegap developer app

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.

like image 288
Danish Jamil Avatar asked Nov 10 '22 16:11

Danish Jamil


1 Answers

$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.

like image 128
Danish Jamil Avatar answered Nov 15 '22 06:11

Danish Jamil