2012-07-11 51 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> 

相關文檔:

相關問題