【发布时间】:2009-07-10 21:09:54
【问题描述】:
我在使用 JQuery 加载外部 JavaScript 时遇到问题。每次我尝试加载此外部文件时,浏览器窗口都会变为空白,并且在 Firefox 中它会重定向到以下内容:
所见即所得://40/http://mydomain.com/myfile.html
我想要做的是将 walkscore 谷歌地图加载到页面上的一个 div 中。我试过使用 $.get() 方法、.load()、$.getScript() 和 $.requireScript() jquery 插件,除了一种情况,当我把 alert() 放在 $.get 之后() 方法。在这种情况下,浏览器不会被重定向到任何地方,并且会在页面上显示 walkscore 地图。
这是我在 head 部分的脚本:
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
function loadWalkScore() { $.get("http://www.walkscore.com/tile/show-tile.php?wsid=87439b0626c9eaeacfd6d8d5598afc13",null,null,"script"); } </script>
页面正文中的脚本:
<div id="contentArea" style="margin: 20px 0px 10px 10px; border: 1px solid #CCC;">
<script type="text/javascript">
var ws_lat = "40.710318";
var ws_lon = "-74.016553";
var ws_width = "630";
loadWalkScore();
</script>
</div>
还请查看我拥有的所有示例(只有第一个有效):
// 1. $.get() - 工作示例,在 $.get() 方法之后有警报
网站。 com/tabs/walkscore-with-alert.html
// 2. $.get() - 与上面完全相同,没有警报,不起作用
网站。 com/tabs/walkscore-get.html
// 3. .load() - 使用 walkscore js 加载 html 文件,不起作用
网站。 com/tabs/walkscore-load.html
// 4. $.getScript() - 不起作用
网站。 com/tabs/walkscore-getscript-external.html
// 5. $.getScript() 本地保存的walkscore js,不起作用
网站。 com/tabs/walkscore-getscript-local.html
// 6. $.requireScript() - 使用 jquery 插件,不起作用
网站。 com/tabs/walkscore-get-plugin.html
【问题讨论】:
-
您正在尝试使用 AJAX 加载另一个 JavaScript 脚本?
-
使用 firebug 检查服务器响应。