【问题标题】:Ajax call never gets called in phonegap for androidAjax 调用永远不会在 Android 的 phonegap 中调用
【发布时间】:2012-08-26 01:45:47
【问题描述】:

我搜索了类似的问题,但从未找到正确的答案。我正在使用 phonegap 和 JQM 为多个平台制作应用程序。我用类似的调用制作了 index.html,即“登录页面”。 Index 的调用有效,但下面的调用从未在我的 android 设备上被调用,即使它在 chrome 和 safari 上都有效。

我检查了服务器日志,“登录”没有问题,但正如我所说,当应该调用下面的函数时,我的 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');
        },
    }); 
});

【问题讨论】:

  • 请同时提供服务器源代码
  • 服务器端运行良好。我很简单,没有来自移动设备的请求。
  • 阅读我的旧帖子。你会得到一个线索stackoverflow.com/questions/11054319/ajax-on-phonegap/…
  • 对不起,我还没有找到答案。你可以再详细一点吗? T 在两个 html 文件中尝试了相同的 ajax 调用。第一个站点 ajax 正确调用,第二个链接站点 ajax 永远不会被调用。为什么?

标签: javascript android ajax cordova jquery-mobile


【解决方案1】:

您的 Android 项目 config.xml 文件中的访问源值是什么?

您的值应如下所示:

<access origin=".*"/>

【讨论】:

【解决方案2】:

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

【讨论】:

  • 如果您不介意我问,问题/解决方法是什么? (用于未来的 stackoverflowers)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-13
  • 2014-04-08
  • 2020-10-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多