簡體   English   中英

CORS + Android Webview,不適用於設備(​​但適用於模擬器)

[英]CORS + Android Webview, doesn't work on device (but does on emulator)

我有一個工作正常的HelloWorld phonegap程序,其中的jquery mobile如下所示: http : //jquerymobile.com/demos/1.1.0/docs/about/getting-started.html 我為此添加了一些JavaScript,以嘗試跨源資源共享:

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

這在模擬器(2.3)上效果很好,jquery.com已通過jquery移動演示加載。 但是,在實際的2.3 Android設備(運行Cyanogen,Galaxy SII,Galaxy Player的T-mobile G2)上,changePage()調用沒有任何作用。

調用$.mobile.changePage()的函數內pageinit像一個壞主意功能的聲音,因為這應該引起無限循環。 $.mobile.changePage()函數初始化指定為target參數的頁面,因此,每次調用$.mobile.changePage() ,也會觸發pageinit事件。

您可能想綁定到mobileinit事件以在初始化jQuery Mobile之前覆蓋$.support.cors變量:

<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>

相關文件:

嘗試使用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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM