Ajax调用永远不会在android的phonegap中被调用

时间:2023-01-01 08:09:07

I searched similar questions but never found a proper answer. I am making app for multiple platforms using phonegap and JQM. I made index.html, which is "login page", with similar call. Index's call works, but the one below never gets called on my android device, even though it works both on chrome and safari.

我搜索了类似的问题,但从未找到合适的答案。我正在使用phonegap和JQM为多个平台制作应用程序。我做了index.html,这是“登录页面”,有类似的调用。索引的调用有效,但下面的调用永远不会在我的Android设备上调用,即使它在chrome和safari上同时工作。

I checked sever logs and there are no problems with "login", but as I said, there is no request from my android device when function below should be called.

我检查了服务器日志,并且“登录”没有问题,但正如我所说,当我的android设备没有请求时,应该调用下面的函数。

    //document.addEventListener("deviceready", onDeviceReady, true);

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

//var onDeviceReady = function(){

$( document ).ready(function (){
        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',
        contentType:  'application/json',
        dataType: 'jsonp json',
        timeout : 10000,

        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');

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

2 个解决方案

#1


0  

What is the access origin value in your Android project config.xml file ?

Android项目config.xml文件中的访问源值是多少?

your value should be as below :

你的价值应该如下:

<access origin=".*"/>

#2


0  

There was a problem with placing script and specific way that jqm work.

放置脚本和jqm工作的具体方法存在问题。

#1


0  

What is the access origin value in your Android project config.xml file ?

Android项目config.xml文件中的访问源值是多少?

your value should be as below :

你的价值应该如下:

<access origin=".*"/>

#2


0  

There was a problem with placing script and specific way that jqm work.

放置脚本和jqm工作的具体方法存在问题。