I'm using Angular's $http service to get some data from a remote data source, but logging out the results to the console gives empty strings.
The function looks as follows:
$http.get('/some/url/')
.success(function(data/*, status, headers, config*/) {
console.log('Success! data: ', data);
})
.error(function(data, status, headers, config) {
console.log('failed http req!');
console.log('data: ', data);
console.log('status: ', status);
console.log('headers: ', JSON.stringify(headers()));
console.log('config: ', JSON.stringify(config));
});
I'm purposfully calling a URL I know does not exist and expecting to get a 404. When running from the browser (using cordova serve
) I see all the error data printed out to the console.log.
I'm using Cordova ~3.4
I've installed the console plugin for Cordova.
I'm viewing the Android device log using adb logcat
set to debugging.
Any ideas?
Update: I tried on all 4 variables to use JSON.stringify, just to see if that might work out of sheer luck in a moment of frustration... left them on the headers() and config since they're objects anyway. I still didn't get any print out on the data or status, which still puzzles me...
Cordova's console.log accepts only one argument (At least on Android) and that's why I've been getting only partial logging. Changing the code to:
$http.get('/some/url/')
.success(function(data/*, status, headers, config*/) {
console.log('Success! data: ' + data);
})
.error(function(data, status, headers, config) {
console.log('failed http req!');
console.log('data: ' + data);
console.log('status: ' + status);
console.log('headers: ' + JSON.stringify(headers()));
console.log('config: ' + JSON.stringify(config));
});
solved the problem.