2012-07-11 53 views
4

我有一个可用的HelloWorld电话程序,jquery mobile如下所述:http://jquerymobile.com/demos/1.1.0/docs/about/getting-started.html。我加了一些JavaScript这与跨源资源共享实验:CORS + Android Webview,不能在设备上工作(但在模拟器上)

<script> 
$(document).bind("pageinit", function() { 
    $.support.cors = true; 
    $.mobile.allowCrossDomainPages = true; 
    $.mobile.changePage("http://jquery.com"); 
}); 
</script> 

这个工程在模拟器(2.3)大,jquery.com被加载在jQuery Mobile的演示。但是,在实际的2.3 Android设备(运行Cyanogen,Galaxy SII,Galaxy Player的T-mobile G2)上,changePage()调用什么也不做。

+0

什么是y我们的缓存和异步字段设置为? – Erol 2012-07-14 04:05:45

回答

1

尝试mobileinit而不是pageinit。因为绑定的事件是普通的jQuery,而对于jQuery mobile,初始化事件是mobileinit。

The $.mobile.allowCrossDomainPages option must be set before any cross-domain request is made so we recommend wrapping this in a mobileinit handler

4

pageinit函数中调用$.mobile.changePage()函数听起来像个坏主意,因为这会导致无限循环。 $.mobile.changePage()函数初始化指定为target参数的页面,因此每次调用$.mobile.changePage()时也会触发pageinit事件。

你可能想绑定到mobileinit事件覆盖$.support.cors变量之前jQuery Mobile的初始化:

<script src="jquery.js"></script> 
<script> 
$(document).bind("mobileinit", function() { 
    $.support.cors = true; 
    $.mobile.allowCrossDomainPages = true; 
    $.mobile.changePage("http://jquery.com"); 
}); 
</script> 
<script src="jquery-mobile.js"></script> 

相关文档:

相关问题