Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PhoneGap,可以';t仅在Android上使用Ajax加载本地.html文件_Android_Jquery_Cordova - Fatal编程技术网

使用PhoneGap,可以';t仅在Android上使用Ajax加载本地.html文件

使用PhoneGap,可以';t仅在Android上使用Ajax加载本地.html文件,android,jquery,cordova,Android,Jquery,Cordova,我使用的是PhoneGap(最新版本),jQuery1.7。我很难通过AJAX将一些html加载到div中。我的问题很简单,我在www/目录中有一个index.html文件。还有一个js文件,用于执行以下操作: $.ajax({ type:"GET", timeout:10000, dataType: "html", async: false, cache: false, url: "file:///android_asset/www/_liqui-cult.html", succ

我使用的是PhoneGap(最新版本),jQuery1.7。我很难通过AJAX将一些html加载到div中。我的问题很简单,我在www/目录中有一个index.html文件。还有一个js文件,用于执行以下操作:

$.ajax({
 type:"GET",
 timeout:10000,
 dataType: "html",
 async: false,
 cache: false,
 url: "file:///android_asset/www/_liqui-cult.html",
 success: function(data) {
  $('#data_details .description').html(data); // never runs
 },
 error: function(xhr,msg){
   alert(xhr.status + ", " + msg);
   if(xhr.status == 0 || xhr.status == "0"){
    alert(xhr.responseText); // always blank, if runs
   }
 }
});
花了一天时间在谷歌上搜索这个错误,我尝试了很多方法,但AJAX调用从未成功。我已经尝试将url更改为简单的
\u liqui-cult.html
(没有基于文件的url)。我也试过
/\u liqui-cult.html

我开始尝试JQuery
$.load
,但这不起作用,所以我切换到更详细的
$.ajax
调用

无论我做什么,我要么得到404作为状态,要么,如果我将url更改为
http://_liqui-cult.html
,我的状态为0,但响应文本中没有任何内容

因此,我将JQuery从等式中去掉,并尝试了一个简单的XMLHttpRequest,如下所示:

var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
  if (xmlhttp.readyState==4 && (xmlhttp.status==200 || xmlhttp.status==0))
  {
    $('#data_details .description').html(xmlhttp.responseText);
    $.mobile.changePage('#screen_detail');
  }
}
xmlhttp.open("GET","_liqui-cult.html", true);
xmlhttp.send(null);
同样,我尝试了所有可能的url模式来映射到html文件。不过,我能得到的最好结果是xmlhttp.responseText为空

那么跨境问题呢?以下是我尝试过的:

同样,我尝试了所有映射到html文件的方法,使用了那些不同的访问源设置,但仍然无法加载html文件


有什么想法吗?

你的项目似乎出了问题。下面的要点是我测试应用程序中的一些文件,它在Android中工作没有任何问题


将用于加载AJAX的html文件的名称从“_liqui-cult.html”更改为相同的名称,但不带下划线“liqui cult.html”,解决了这个问题。

顺便说一句,我的目标是Android 3,API级别11。同样的代码在iOS中也能正常工作。非常感谢您的关注。事实证明,问题在于AJAX文件名中的下划线。把名字改成“liqui cult.html”解决了这个问题。哇,这救了我的命。谢谢我很困惑;为什么这能解决问题?