Javascript jQuery/AJAX/parsererror/XAMPP/Win8.1/IE11/Chrome
我知道关于“parsererror”有一百万个问题,但似乎找不到一个对我的情况有意义的答案。这是我的病态代码:Javascript jQuery/AJAX/parsererror/XAMPP/Win8.1/IE11/Chrome,javascript,jquery,ajax,parse-error,Javascript,Jquery,Ajax,Parse Error,我知道关于“parsererror”有一百万个问题,但似乎找不到一个对我的情况有意义的答案。这是我的病态代码: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Test</title> <script type="text/javascript" src=
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Test</title>
<script type="text/javascript" src="jquery-2.1.1.min.js"></script>
<script type="text/javascript">
$.ajax({
url: 'http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0',
dataType: 'jsonp',
contentType: 'application/jsonp; charset=utf-8',
jsonp: 'onscriptload',
success: function(data, textStatus)
{
console.log("Success.");
var MM = Microsoft.Maps;
var map = new MM.Map($('#mapDiv')[0],
{
credentials: 'a valid bing maps key'
});
},
error: function(xOptions, textStatus)
{
console.log(JSON.stringify(xOptions) + ' ' + textStatus);
}
});
</script>
</head>
<body>
<div id="mapDiv" class="map"></div>
</body>
</html>
试验
$.ajax({
网址:'http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0',
数据类型:“jsonp”,
contentType:'application/jsonp;charset=utf-8',
jsonp:'onscriptload',
成功:功能(数据、文本状态)
{
console.log(“Success”);
var MM=Microsoft.Maps;
var map=new MM.map($('#mapDiv')[0],
{
凭据:“有效的bing映射密钥”
});
},
错误:函数(xOptions,textStatus)
{
log(JSON.stringify(xOptions)+''+textStatus);
}
});
“error”部分被触发,并返回{“readyState”:4,“status”:200,“statusText”:“load”}parserror
,我很难让它正常工作。IE11和Chrome中完全相同的错误/行为。这是最有用的文章(),但是“onscriptload”应该已经是一个内置函数,我不应该(重新)定义/重载,不是吗?任何帮助都很感激…ajax请求只是为了按需加载bing地图库而不是页面加载,这是一种“黑客行为”。我推荐一种典型的方法,如:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function loadMap() {
// Initialize the map
var map = new Microsoft.Maps.Map(document.getElementById("map"),
{
credentials: "BING MAPS KEY HERE"
});
//load the pushpins here
}
</script>
</head>
<body onload="loadMap();">
<div id="map"></div>
</body>
</html>
函数loadMap(){
//初始化映射
var map=new Microsoft.Maps.map(document.getElementById(“map”),
{
凭据:“BING地图密钥在此”
});
//把图钉装在这里
}
该url是一个脚本。为什么要把它当作jsonp呢?我试着按照代码示例来做