jQueryMobile运行在Android上/ PhoneGap的拒绝.load /阿贾克斯 [英] jQueryMobile running on Android / PhoneGap refuses .load / .ajax
问题描述
我真的很讨厌问,我觉得被问过一千遍的问题。这是那些问题,我觉得别人一定都遇到过的,<一个href=\"http://stackoverflow.com/questions/7539079/jquery-load-function-does-not-work-under-phonegap\">but <一href=\"http://stackoverflow.com/questions/7539079/jquery-load-function-does-not-work-under-phonegap\">having <一href=\"http://stackoverflow.com/questions/9418818/phonegap-jqm-problems-with-local-files-on-android\">searched 堆栈 <一个href=\"http://stackoverflow.com/questions/8650268/android-phonegap-and-jquerymobile-integration\">overflow,没有所谓的解决方案为我工作,所以我必须做一些错误的......
我有一个非常简单的应用程序设置。的index.htm和terms.htm。有一个在TEST.HTM一些文本数据。我同时设置 $ support.cors = TRUE;
和 $ mobile.allowCrossDomainPages = TRUE;
在适当的时候之后的东西已加载。
起初,我尝试使用 $('#elementid')负载('terms.htm')加载terms.htm的数据转换成一个元素指标之内;
(包括测试指标都在同一个根/资产/ WWW /目录下,我的WebView负荷指数OnCreate中),但绝对什么也没有发生。所以,我选择了尝试阿贾克斯,这样我至少可以得到一个错误信息,我得到的是错误。当然,也可以上加载DroidGap与JQ当地文字的资产?
$('#头')负载('terms.htm')。
$阿贾克斯({
键入:GET,
超时:10000,
异步:假的,
网址:terms.htm
成功:功能(数据){
$('#头)HTML(数据)。
},
错误:功能(XHR,味精){
警报(MSG);
}
});
它仅仅是一个长镜头,但你说的我同时设置$ .support.cors = TRUE;和$ .mobile.allowCrossDomainPages = TRUE ;在东西加载后的适当时间的。 jQuery的移动文件说href=\"http://jquerymobile.com/test/docs/api/globalconfig.html\" rel=\"nofollow\">你必须的设置您的全局配置的负载JQM :
由于mobileinit事件被立即触发,你需要你的绑定事件
jQuery Mobile的前处理程序被加载。链接到您的JavaScript文件在以下
顺序:
块引用>&LT;脚本SRC =jquery.js和&GT;&LT; / SCRIPT&GT;
&LT;脚本SRC =定制scripting.js&GT;&LT; / SCRIPT&GT;
&LT;脚本SRC =jQuery的-mobile.js&GT;&LT; / SCRIPT&GT;在你的情况,这将是:
&LT;脚本SRC =jquery.js和&GT;&LT; / SCRIPT&GT;
&LT;脚本&GT;
(文档)$ .bind(mobileinit功能(){
$ .support.cors = TRUE;
$ .mobile.allowCrossDomainPages = TRUE;
});
&LT; / SCRIPT&GT;
&LT;脚本SRC =jQuery的-mobile.js&GT;&LT; / SCRIPT&GT;就像我说的,只是猜测...
I really hate asking questions that I feel were asked a thousand times before. This is one of those questions I feel others must have encountered, but having searched stack overflow, none of the supposed solutions work for me so I must be doing something wrong.....
I have an extremely simple app setup. index.htm, and terms.htm. There is some textual data in test.htm. I set both
$.support.cors = true;
and$.mobile.allowCrossDomainPages = true;
at the appropriate time after stuff has loaded.At first I tried loading terms.htm's data into an element within index using
$('#elementid').load('terms.htm');
(both test and index are in the same root /assets/www/ directory, and my webview loads index oncreate) but absolutely nothing was happening. So I opted to try .ajax so that I could at least get an error message, and all I get is 'error'. Surely, it is possible to load local textual assets with JQ on DroidGap?$('#header').load('terms.htm'); $.ajax({ type:"GET", timeout:10000, async: false, url: "terms.htm", success: function(data) { $('#header').html(data); }, error: function(xhr,msg){ alert( msg); } });
解决方案it is just a long shot, but you say "I set both $.support.cors = true; and $.mobile.allowCrossDomainPages = true; at the appropriate time after stuff has loaded.". The jQuery mobile documentation says you have to set your global configuration before you load JQM:
Because the mobileinit event is triggered immediately, you'll need to bind your event handler before jQuery Mobile is loaded. Link to your JavaScript files in the following order:
<script src="jquery.js"></script> <script src="custom-scripting.js"></script> <script src="jquery-mobile.js"></script>
In your case this would be:
<script src="jquery.js"></script> <script> $(document).bind("mobileinit", function(){ $.support.cors = true; $.mobile.allowCrossDomainPages = true; }); </script> <script src="jquery-mobile.js"></script>
Like I said, just a guess ...
这篇关于jQueryMobile运行在Android上/ PhoneGap的拒绝.load /阿贾克斯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!