我有一小段调用网络服务的代码,当我在Firefox或Chrome中使用它时它可以正常工作,但是当我在Internet Explorer中使用它时,没有任何工作。
这是你的代码
<html>
<head>
<title>Parsing XML Test</title>
<style>
body {
padding: 0;
margin: 0;
}
html, body, #map {
height: 100%;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
function initialize() {
var query = 'service_url';
$.ajax({
type: "GET",
url: query,
dataType: 'xml',
success: function (data) {
alert("OK")
},
error: function (response, textStatus, errorThrown) {
alert(errorThrown);
}
});
}
</script>
</head>
<body onload="initialize()">
<div id="map"></div>
</body>
</html>
任何人都可以帮我修改代码吗?
非常感谢你!!
切萨雷
答案 0 :(得分:0)
我已经以这种方式解决了......
<html>
<head>
<title>Parsing XML Test</title>
<style>
body {
padding: 0;
margin: 0;
}
html, body, #map {
height: 100%;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
function initialize() {
var browser = navigator.userAgent.toLowerCase();
var isIE = (browser.indexOf("msie")>-1 || browser.indexOf("trident")>-1);
if (isIE && window.XDomainRequest) {
if (window.XDomainRequest) {
var query = 'service_url';
var xdr = new XDomainRequest();
if (xdr) {
xdr.onload = function () {
alert("OK");
alert(xdr.responseText);
}
xdr.onerror = function () {
alert("KO");
}
xdr.open('GET', query);
xdr.send();
}
}
}
else {
var query = var query = 'service_url';
$.ajax({
type: "GET",
url: query,
dataType: "text",
crossDomain: true,
success: function (data) {
alert("OK");
alert(data);
},
error: function (response, textStatus, errorThrown) {
alert("KO");
alert(errorThrown);
}
});
}
}
</script>
</head>
<body onload="initialize()">
<div id="map"></div>
</body>
现在它正在所有浏览器上工作!
我希望这可能有用..