Reputation: 171
I am developing an app using phonegap. I am using the edmunds API to get pictures of cars. The API works fine on the browser but when I run it on the device it does not show the images. Does anyone know the reason? And is there a way to debug on the device for javascript?
Here is the code:
<script>
window.sdkAsyncInit = function() {
// Instantiate the SDK
var res = new EDMUNDSAPI('xxxx');
// Optional parameters
var options = {};
var style;
// Callback function to be called when the API response is returned
function success(res) {
style = res.styles[0].id;
console.log(style);
showimage(style);
};
function showimage(style){
var opt = {
"styleId": ""+style+"",
"comparator": "simple"
};
console.log(opt);
res.api('/v1/api/vehiclephoto/service/findphotosbystyleid', opt, success2, fail);
}
function success2(res){
var body = document.getElementById('image');
body.innerHTML = "<img src='http://media.ed.edmunds-media.com"+ res[0].photoSrcs[0] +"' />";
}
function fail(data) {
console.log(data);
}
// Fire the API call
var make = localStorage.getItem('make');
var model = localStorage.getItem('model');
var year = localStorage.getItem('year');
console.log(make+model+year);
res.api('/api/vehicle/v2/'+make+'/'+model+'/'+year+'/styles', options, success, fail);
// Additional initialization code such as adding Event Listeners goes here
};
// Load the SDK asynchronously
(function(d, s, id){
var js, sdkjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "./edmunds.api.sdk.js";
sdkjs.parentNode.insertBefore(js, sdkjs);
}(document, 'script', 'edmunds-jssdk'));
</script>
Upvotes: 1
Views: 714
Reputation: 171
the API was getting the protocol from the window which was not working for the phone app changed it to https and it worked.
Upvotes: 1
Reputation: 16060
You can use:
http://debug.phonegap.com/ (also known as weinre)
Did you enable the API in the whitelist?
And do you have an adb logcat?
Upvotes: 3