单击时 jquery 加载脚本
我正在尝试使用此代码从另一个站点加载 JavaScript 脚本,但它不起作用!
$("#random").click(function(){
$.getScript("http://www.themoviequotes.com/widgets/javascript?n=1&l=1&g=3");
});
我有一个 id 为“movie”的 div,我试图将上面的脚本中的内容加载到其中!
I'm attempting to load a javascript script from another site with this code but it isnt working!
$("#random").click(function(){
$.getScript("http://www.themoviequotes.com/widgets/javascript?n=1&l=1&g=3");
});
I have a div with an id of "movie" in which i'm trying to load the content into from the above script!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在
text/html
模式下,元素本质上是 CDATA。因此
&
表示&
而不是&
。不要在
元素内使用 HTML 实体。
(如果您正在编写 XHTML 并将其作为 text/html 提供,则 关于 XHTML 媒体的指南类型,特别注意嵌入样式表和脚本< /a>。)
由于您已将
&
替换为&
,因此您正在从服务器无法识别的 URL 获取数据。然而,即使你确实改变了这一点,它仍然不起作用。由于某种原因,该脚本被用作
text/html
而不是application/javascript
,它包含一个document.write
语句。如果文档仍处于打开状态以进行追加,则此操作将写入文档的末尾(因此对于替换页面的一部分是无用的),否则将完全替换它。jQuery.load
不会有帮助,因为它期望一些内容放入元素中(而不是要执行的脚本)并且(据我所知)没有跨域功能(仅适用于非常新的浏览器,并且仅使用发送正确 HTTP 标头的服务器)。In
text/html
mode,<script>
elements are intrinsically CDATA. Thus&
means&
and not&
.Do not use HTML entities inside
<script>
elements.(If you are writing XHTML and serving it as text/html, then the guidance on XHTML media types with special attention for the section on embedded style sheets and scripts.)
Since you have replaced
&
with&
, you are fetching data from a URL that the server doesn't recognize.However, even if you did change that, it still wouldn't work. The script, which for some reason is being served as
text/html
instead ofapplication/javascript
, contains adocument.write
statement. This writes to the end of the document (so it is useless for replacing a section of the page) if the document is still open for appending, or replaces it entirely otherwise.jQuery.load
wouldn't help since that expects some content to drop into an element (not a script to execute) and (as far as I know) has no cross-domain capabilities (which only work in very new browsers and only with servers which send the right HTTP headers).使用这个:
URL 错误。
Use this:
The URL was wrong.
看起来您的网址错误,
请删除&
http://www.themoviequotes.com/widgets /javascript?n=1&n=l=1&g=3
looks like your url is wrong
remove &
http://www.themoviequotes.com/widgets/javascript?n=1&n=l=1&g=3