我遇到了浏览器在我的页面上报告 javaScript 错误的问题。尽管该页面功能齐全,但我更喜欢没有 javaScript 错误,因为它对用户来说看起来很糟糕。
我在 FF 中遇到的错误是:
Error: SyntaxError: missing } in XML expression
Source File: http://localhost/resources/adagiotips.php
Line: 14, Column: 4
Source Code:
});
我在 jQuery 中使用 getScript() 函数来定位一个 php 页面,该页面呈现包含 javascript 和 html 的代码。然后我使用此页面的输出来填充 div 的内部 html。这是我在第 1 页上的内容:
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery.getScript('/includes/showmehow_videolist.php?sort=recent&type=desc', function(output){
jQuery("#apple").html(output);
});
});
</script>
<div id="apple">content will populate here</div>
在“showmehow_videolist.php”上,我有一个 php while 循环,它编写了一个 jQuery 函数列表和一些 html。代码看起来像这样:
<script type="text/javascript">
jQuery(document).ready(function(){
<?PHP
$result4 = mysql_query("SELECT * FROM videos")or die(mysql_error());
while($row4 = mysql_fetch_array($result4)){
?>
jQuery("#video_<?=$row4['vid_id']?>").fancybox({
'width' : <?=$new_width_parsed?>,
'height' : <?=$new_height_parsed?>,
'autoScale' : false,
'transitionIn' : 'elastic',
'transitionOut' : 'none',
'type' : 'iframe',
'scrolling' : 'no',
'overlayColor' : '#000',
'overlayOpacity' : 0.6
});
<?
}//end while
?>
}); //end document.ready function
</script>
<div>some content</div>
当我从第 2 页中删除 javascript 部分时,我在 FF 中得到一个不同的错误:
Error: SyntaxError: XML can't be the whole program
Source File: http://localhost/resources/adagiotips.php
Line: 1136, Column: 6
Source Code:
</div>
有任何想法吗?问题是因为我正在用javascript填充div的innerhtml ...来自javascript吗?就像我说的,一切正常,只是了解浏览器为什么告诉我有错误。
任何帮助将不胜感激,谢谢。
/includes/showmehow_videolist.php 的输出:
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#video_82").fancybox({
'width' : 782,
'height' : 720,
'autoScale' : false,
'transitionIn' : 'elastic',
'transitionOut' : 'none',
'type' : 'iframe',
'scrolling' : 'no',
'overlayColor' : '#000',
'overlayOpacity' : 0.6
});
jQuery("#video_83").fancybox({
'width' : 782,
'height' : 720,
'autoScale' : false,
'transitionIn' : 'elastic',
'transitionOut' : 'none',
'type' : 'iframe',
'scrolling' : 'no',
'overlayColor' : '#000',
'overlayOpacity' : 0.6
});
jQuery("#video_84").fancybox({
'width' : 782,
'height' : 720,
'autoScale' : false,
'transitionIn' : 'elastic',
'transitionOut' : 'none',
'type' : 'iframe',
'scrolling' : 'no',
'overlayColor' : '#000',
'overlayOpacity' : 0.6
});
}); //end document.ready function
</script>
<div style="overflow-x:hidden; overflow-y: auto; height:350px; width:725px;" id="main_div_of_video_links">
<div class="tab1">
<div class="tab2">
<span class="h2_standard">5</span> <span class="sm">views</span>
</div>
<div class="tab3">
<img src="/images/icon_video_sm.gif" alt="History - Show Me How Video!" /> <a id="video_181" href="../video_pop.php?id=181" class="newAStyle">Adagio OrderEntry History</a>
<!--<img src="/images/flame_sm.png" />--> <img src="/images/new_icon.png" />
</div>
<div class="tab4">
<span class="sm"><em>Added: </em>Jul 23 2012</span>
</div>
<div style="clear:both"></div>
</div>
<div class="tab1">
<div class="tab2">
<span class="h2_standard">5</span> <span class="sm">views</span>
</div>
<div class="tab3">
<img src="/images/icon_video_sm.gif" alt="Alternate Price Lists - Show Me How Video!" /> <a id="video_165" href="../video_pop.php?id=165" class="newAStyle">Adagio Inventory Alternate Price Lists</a>
<!--<img src="/images/flame_sm.png" />--> <img src="/images/new_icon.png" />
</div>
<div class="tab4">
<span class="sm"><em>Added: </em>Jul 13 2012</span>
</div>
<div style="clear:both"></div>
</div>
<div class="tab1">
<div class="tab2">
<span class="h2_standard">1</span> <span class="sm">views</span>
</div>
<div class="tab3">
<img src="/images/icon_video_sm.gif" alt="Special Prices - Show Me How Video!" /> <a id="video_166" href="../video_pop.php?id=166" class="newAStyle">Adagio OrderEntry Special Prices</a>
<!--<img src="/images/flame_sm.png" />--> <img src="/images/new_icon.png" />
</div>
<div class="tab4">
<span class="sm"><em>Added: </em>Jul 13 2012</span>
</div>
<div style="clear:both"></div>
</div>
</div>