1

我正在制作一个 jQuery Mobile 和 PhonGap 应用程序。它通过使用 JSONP 的 AJAX 调用连接到服务器端 Web 服务(我知道跨域问题,尽管我的 android 开发人员没有遇到它)。我正在使用 PhoneGap Build 为许多操作系统准备应用程序。

这是我的问题:我制作了一个 index.html,它对服务器进行 AJAX 调用。我收到了回复,我被重定向到 main.html。它在 chrome、safari 和我的 Android 设备上运行良好。

在第二个站点:main.html,我有类似的请求(我也尝试过相同的请求),但在 Android 设备上没有被调用。但是它在 Chrome 和 Safari 上都可以正常工作。

我尝试关闭缓存,授予适当的权限,将其添加到 config.xml。请注意,我还尝试通过 eclipse 编译我的应用程序,但没有结果我添加到 /res/xml/cordova.xml。

我检查了服务器日志,没有来自第二个站点的请求。这是代码:

注意:我还根据 PhoneGap 阅读了 jQuery 移动文档。更改 $(document).ready 并不能解决问题。此构造适用于 index.html 网站。

$( document ).bind( "mobileinit", function(){
        $.support.cors = true;
        $.mobile.allowCrossDomainPages = true;
        $.mobile.loadingMessageTextVisible = true; 
        $.mobile.showPageLoadingMsg();
        console.log('Start Strony');
})


$( document ).ready(function (){ //
        $.ajaxSetup ({
        cache: false
    });
        console.log('Start');
        $.support.cors = true;
        $.mobile.allowCrossDomainPages = true;
        $.ajax({                                                                   
        crossDomain: true,
        type: 'GET',
        url: 'http://ip/services/rest/contact/list', 
        callback: 'jsonpCallback',
        jsonpCallback: 'jsonpCallback',
        jsonp: '_jsonp',
        scriptCharset: "utf-8",
        contentType:  'application/json',
        dataType: 'jsonp',
        timeout : 5000,

        success: function(data){

            var html ='';
            console.log('Success');
            $.each(data.response, function(key, value) {
            html += '<li><a class=contact href="#" id="' + data.response[key].id + '" ><h1>' + data.response[key].label + '</h1><p>'+ data.response[key].customerName + '</p><p>' + data.response[key].phone + ', ' + data.response[key].email + '</p></a></li>';
            $('#ul_id').append($(html));
            html='';
            console.log('conatct');
            });
            $('#ul_id').trigger('create');    
            $('#ul_id').listview('refresh');
            //localStorage.setItem('idCustomerValue', data.re);

        },
        error: function (xhr, ajaxOptions, thrownError){
            alert("Status: " + xhr.status + ", Ajax option: " + ajaxOptions + ", Thrown error: " + thrownError);
            //location.reload();
            console.log('Blad');
        },
    }); 
});

不幸的是,我无法为您提供服务器端代码。服务器设置正确。正如我提到的 Chrome 和 Safari 工作。

4

1 回答 1

0

问题是在 JQM 中链接时的 pageinit 事件和特定行为。

于 2012-09-11T13:52:42.667 回答