2012-06-27 28 views
0

删除的Javascript我正在写使用jQuery和PhoneGap的jQuery的AJAX上的PhoneGap

一个应用程序在我的javascript代码我呼吁$就要求一些应用程序的部分,以我的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> 

,问题是,这个代码执行时,它不会插入脚本标签到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> 

任何想法,为什么出现这种情况?

回答

0

如果我没有弄错,这是因为你不能附加或使用innerHTML插入脚本标记。我建议改变这个Ajax调用的位置,在插入将要进行的现场,然后转产

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

document.write(data);