API似乎不在移动浏览器上运行

时间:2017-06-08 04:06:08

标签: javascript android ios angularjs jquery-mobile

我正在尝试调试API问题,我似乎无法让它在移动浏览器(iOS或Android)上运行。我正在使用的API是缩短URL的Bitly API。到目前为止,我已经成功开发了桌面浏览器(Chrome,Mozilla,Safari)。但如果我尝试在移动浏览器上检查它,它似乎没有运行。控制台上没有任何错误。

目前在我的Web App中使用Angular 1。在这里你可以看到这是一个放在控制器内的API。我在页面/视图完成加载后使用$timeout来运行API。

更新

所以我尝试将API移到$timeout(function())之外,输出仍然相同。它在桌面上显示结果,但在移动浏览器上显示无结果

    var base_url      = window.location.origin,
        hash_bang     = "/#/sign-up?referral=",
        login         = "login",
        api_key       = "api_key",
        ref_code = document.getElementById('input-refcode').value;

        function get_short_url(login, api_key, func) {
            $.getJSON(
                "https://api-ssl.bitly.com//v3/shorten?callback=?", 
                { 
                    "format": "json",
                    "apiKey": api_key,
                    "login": login,
                    "longUrl": base_url + hash_bang + ref_code
                },

                function(response)
                {
                    func(response.data.url);
                }
            );
        }

    get_short_url(login, api_key, function(short_url) {

        $('#input-refcode').val(short_url);
        $('.url-code').val(short_url);
        alert(short_url);
    });






    <div class="invite-code" ng-init="code()">

        <input class="input url-code" disabled=true id="input-urlcode" />

        <input class="input referral-code" disabled="true" ng-model="account.referral_code_string" id="input-refcode" />

        <button class="copy-code-btn">Copy URL</button>
    </div>
var ctrls = angular.module('elstudio.controllers.site');

ctrls.controller('FreeRidesCtrl', function ($scope, $location, $timeout, $window, UserService, AuthService,
                                          UserPackageService, ReferralService) {

    // $timeout(function() {
    //   alert('test');
    // })

    $timeout(function(){
        var base_url      = window.location.origin,
            hash_bang     = "/#/sign-up?referral=",
            login         = "login",
            api_key       = "api_key",
            ref_code = document.getElementById('input-refcode').value;

            function get_short_url(login, api_key, func) {
                $.getJSON(
                    "https://api-ssl.bitly.com//v3/shorten?callback=?", 
                    { 
                        "format": "json",
                        "apiKey": api_key,
                        "login": login,
                        "longUrl": base_url + hash_bang + ref_code
                    },

                    function(response)
                    {
                        func(response.data.url);
                    }
                );
            }

        get_short_url(login, api_key, function(short_url) {

            $('#input-refcode').val(short_url);
            $('.url-code').val(short_url);
            alert(short_url);
        });

    }); //note, no time parameter



  }
});

以下是桌面输出的屏幕截图。正如您所看到的那样,红色笔划中显示了有点的API

enter image description here

但如果我尝试在移动浏览器上查看它。文本框中缺少位输出 enter image description here

我甚至尝试过使用alert。在桌面上它会提示javascript alert,但在移动设备上它不会触发alert

0 个答案:

没有答案
相关问题