我正在使用 phonegap 开发一个应用程序。我正在使用 edmunds API 来获取汽车的图片。该 API 在浏览器上运行良好,但是当我在设备上运行它时,它不显示图像。有谁知道原因?有没有办法在设备上调试javascript?
这是代码:
<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>