Google Api异步回调失败
Google Api Asynch Callback Failed
我得到一个请求的内容:
function httpGet(theUrl)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false );
xmlHttp.send( null );
alert(xmlHttp.status);
return xmlHttp.responseText;
}
内容被解析到我的新网站后:
$Test = httpGet("www.content.com");
document.getElementById("div_content").innerHTML = document.getElementById("div_content").innerHTML + $Test;
在此之后,我将使用谷歌api asynch与回调,但回调函数抛出一个错误
loadScriptFunc('https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&callback=loadScript');
错误是:window.loadScript is not a function
我已经用jquery $做过了。这对我很有效。
编辑:函数是这样加载的:
if(document.getElementById('map_canvas')){
loadScriptFunc('https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&callback=loadScript');
}
函数本身看起来像:
function loadScriptFunc(url)
{
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
head.appendChild(script);
}
loadScript函数是这样的:
function loadScript() {
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox.js';
head.appendChild(script);
bLoaded = true;
window.setTimeout("activateMap()", 100);
}
loadScript Functions属于我的map的模板文件。这个代码已经为我工作与jquery - $。获取函数相同的回调等等。但是我不允许使用jquery…
Edit2:我在网上找到了一些东西,我想我知道问题出在哪里了。
我已经成功地使用了jQuery.load(),因为它执行JavaScript代码块和资源,这些代码块和资源存在于获取的内容中。抱歉,没有演示!
我想我不能从XMLHttpRequest执行代码,有人知道另一个js方法从Url获得一些内容吗??
啊,我知道怎么回事了。这是谷歌地图告诉你它找不到loadScript()。
你告诉Google地图:maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&callback=loadScript
看看发生了什么;我告诉Google Maps调用initialize。
<style>
#map_canvas {width: 400px; height: 400px;}
</style>
<div id="map_canvas"></div>
<script>
function initialize() {
var my_position = new google.maps.LatLng(50.5, 4.5);
var map = new google.maps.Map(document.getElementById('map_canvas'), {
center: my_position,
zoom: 7
});
}
function loadScriptFunc(url) {
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
head.appendChild(script);
}
if(document.getElementById('map_canvas')) {
loadScriptFunc('https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&callback=initialize');
}
</script>
相关文章:
- 当我的单元测试失败时,回调被调用了两次
- AJAX 回调在 Firefox 中失败
- 客户端如何知道发射是否失败?socket.emit()有回调吗
- 返回按钮回调函数在特定情况下失败或未启动
- ajax中的refrer函数名,失败时反向回调
- IE中的jQuery load()回调失败
- 咖啡脚本化的 ajax 调用结果在实际成功时失败回调
- 为什么 Ajax 请求成功,但最终以失败回调告终
- rsvp.js 如何处理被拒绝的承诺和失败回调链
- Corodva 文件读取执行成功和失败回调
- 语义 UI 在成功时,在表单验证时未触发失败回调
- .post()失败回调函数
- 在Jasmine单元测试中,如何强制失败回调来触发失败请求
- 虽然执行了Ajax请求,但调用了失败回调,服务器返回200个数据
- jquery.ajax究竟什么时候运行失败回调
- BreezeJS失败回调导致'undefined不是对象错误'例外
- jQuery ajax-只有在所有重试都失败时才触发失败回调函数
- Breeze entityManager调用失败回调,即使成功
- JQuery ajax()完成/失败回调在状态200时未返回
- jQuery.post() 失败回调函数