gpt4 book ai didi

Javascript 网页期望至少加载一张 map ,但实际上无法加载任何内容

转载 作者:行者123 更新时间:2023-11-30 18:33:45 24 4
gpt4 key购买 nike

下面是嵌入了 Javascript 的 html 页面。 Map API Key 对我的 web 域有效,只有当我隐藏所有 Javascript 函数并保留 initialize() 时页面才能加载 map ,就像一些 Google 的官方示例代码一样,
否则我什么也看不到页面加载后(即空白页)。
谁能帮我找出原因?

谢谢!

<html>   
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Real-time iphone tracker</title>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAzcrhlFUxvQMBI3qYkY87zhStzVKTwp4tXCAZpL7xj82pGpEoixSAvciDeL2RO_S1xLoGgxKBpbG6HQ&sensor=true"
type="text/javascript"></script>
<script type="text/javascript">

var xmlobj;
function createXMLHttpRequest(){
if(window.ActiveXObject)
{
return new ActiveXObject("Microsoft.XMLHTTP");
}

else if(window.XMLHttpRequest)
{
return = new XMLHttpRequest();
}
}

function sendRequest(){

xmlobj = createXMLHttpRequest();
if(!xmlobj){
alert('The browser is not compatible with XMLHttpRequest');
return 0;
}
var indexurl = "index.php";
xmlobj.onreadystatechange = stateHandler;
xmlobj.open("GET", indexurl, true);
xmlobj.send(null);

}
function stateHandler(){
if(xmlobj.readyState == 4 && xmlobj.status == 200){
document.getElementById("map_data").innerHTML= xmlobj.responseText;
}
}

function initialize() {
if (GBrowserIsCompatible()) {
sendRequest();
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(22.37664, 114.184902), 13);
map.setUIToDefault();

var bounds = map.getBounds();
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
var lngSpan = northEast.lng() - southWest.lng();
var latSpan = northEast.lat() - southWest.lat();
for (var i = 0; i < 10; i++) {
var point = new GLatLng(southWest.lat() + latSpan * Math.random(),
southWest.lng() + lngSpan * Math.random());
map.addOverlay(new GMarker(point));
}
}
}
</script>
</head>
<body onload="initialize()" >
<div id="map_canvas" style="width: 500px; height: 300px"></div>
<br>
<div> id="map_data" ></div>

</body>
</html>

最佳答案

您的 JavaScript 中存在错误。 createXMLHttpRequest 应该是这样的:

function createXMLHttpRequest(){
if(window.ActiveXObject)
{
return new ActiveXObject("Microsoft.XMLHTTP");
}

else if(window.XMLHttpRequest)
{
return new XMLHttpRequest();
}
}

注意你已经写了:

return = new XMLHttpRequest();

关于Javascript 网页期望至少加载一张 map ,但实际上无法加载任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8870156/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com