1

我正在使用 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>
4

2 回答 2

3

您可以使用:

http://debug.phonegap.com/(也称为 weinre)

您是否在白名单中启用了 API?

你有 adb logcat 吗?

于 2013-10-22T21:00:53.460 回答
1

API 正在从不适用于手机应用程序的窗口获取协议,将其更改为 https 并且可以正常工作。

于 2013-10-22T23:57:34.863 回答