栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

jQuery getScript返回解析错误异常

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

jQuery getScript返回解析错误异常

该错误是由以下事实引起的:希望使用可以将Google Maps API加载到头部

<scriptsrc="http://maps.google.com/maps/api/js?sensor=true"></script>

如果您由于某种原因不能做到这一点,那么仍然有希望。Google Maps
API不起作用,因为它用于

document.write
在页面中注入依赖项。要使代码正常工作,您可以覆盖本机
document.write
方法。

演示:http://jsfiddle.net/ZmtMr/

var doc_write = document.write; // Remember original method;document.write = function(s) {$(s).appendTo('body')};$.getscript('http://maps.google.com/maps/api/js?sensor=true').done(function() {    $.getscript('../js/gomap.js').done(function() {        alert('gomap loaded');        document.write = doc_write; // Restore method    }).fail(function(jqxhr, settings, exception) {        alert(exception); // this gets shown        document.write = doc_write; // Restore method    });}).fail(function() {    alert('failed to load google maps');});


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/609020.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号