簡體   English   中英

jQuery AJAX刪除了Phonegap上的Javascript

[英]jQuery AJAX removes Javascript on Phonegap

我正在使用jQuery和Phonegap編寫應用程序

在我的JavaScript代碼上,我調用$ .ajax向我的Web服務器請求該應用程序的某些部分。 這些部分基本上是我插入DOM中的html代碼段。 這些代碼段包含與該部分本身相關的javascript代碼(該代碼是動態生成的,這就是為什么我不將其包含在應用程序的主js文件中)

我使用以下代碼調用這些部分:

//...
$.ajax(
            url,
            {
                type: 'GET',
                success: function(data){
                    $('#content').html(data);
                },
                error: function(jqXHR, textStatus, errorThrown) {
                    //...
                }
            });
//...

從Web服務器返回的數據如下所示:

<div>...<div>
<script type="text/javascript">
$(document).ready(function() {
   //some code to be executed when this section loads
   //this is dynamically generated
});
</script>

現在的問題是,當執行此代碼時,它不會將SCRIPT標記插入DOM(僅html部分)。

這在Chrome上運行得很好,但是當我在模擬器上(使用Ripple)對其進行測試時卻無法。

我認為這可能是安全檢查,但不確定。

我的config.xml具有:

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" 
        xmlns:gap = "http://phonegap.com/ns/1.0" 
        version="0.1.1"
        versionCode="1"
        id="com.company.prod">  
    <name>...</name>
    <author>...</author>
    <description>...</description>



    <gap:splash src="splash.png" />

    <content src="index.html"/>
    <access uri="*" subdomains="true"/>

    <feature name="http://api.phonegap.com/1.0/battery"/> 
    <feature name="http://api.phonegap.com/1.0/geolocation"/> 
    <feature name="http://api.phonegap.com/1.0/network"/>
    <feature name="http://api.phonegap.com/1.0/notification"/>

</widget>

知道為什么會這樣嗎?

如果我沒記錯的話,這是因為您不能追加或使用innerHTML插入腳本標簽。 我建議將這個ajax調用的位置更改為將要插入的位置,然后更改行

$('#content').html(data);

document.write(data);

暫無
暫無

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

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