[英]Jquery Rest Service response works only for Chrome browser but not in IE or FF
When visiting the site http://www.dentalo.se you should see this image. 当访问站点http://www.dentalo.se时,您应该看到此图像。
I'm a calling a RestService at http://www.dentalo.se/RestService/Dentalo.svc/Companies and I know it working and getting a response. 我正在致电http://www.dentalo.se/RestService/Dentalo.svc/Companies上的RestService,我知道它可以正常工作并得到响应。 I have tested the service. 我已经测试了这项服务。
I'm using Google Maps to render location for the Google maps. 我正在使用Google Maps渲染Google Maps的位置。 It renders location when using Chrome browser. 使用Chrome浏览器时,它会显示位置。 But I cannot understand why it doesn't work in Firefox, Internet Explorer . 但是我不明白为什么它不能在Firefox,Internet Explorer中工作 。 On mobile devices it doesn't work on any browser even chrome . 在移动设备上,即使在chrome上,它也无法在任何浏览器上运行。
This is the error message I receive in Firefox. 这是我在Firefox中收到的错误消息。 If just visit http://www.dentalo.se you will see the error. 如果仅访问http://www.dentalo.se,您将看到错误。 I only want to add the relevant code. 我只想添加相关代码。 If you need more code tell me. 如果您需要更多代码,请告诉我。
sg = [object Object], url = error, line = [Exception... "Failure" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://dentalo.se/assets/plugins/jquery-1.10.2.min.js :: .send :: line 6" data: no] sg = [对象对象],URL =错误,行= [异常...“失败” nsresult:“ 0x80004005(NS_ERROR_FAILURE)”“位置:” JS框架:: http://dentalo.se/assets/plugins/jquery- 1.10.2.min.js :: .send ::第6行“数据:否]
This some JavaScript code that I have included. 这是我包含的一些JavaScript代码。
<script src="/assets/plugins/jquery-1.10.2.min.js" type="text/javascript"></script>
<!-- Start Google Map JavaScript -->
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true&language=sv"></script>
<script src="/assets/plugins/gmaps/gmaps.js" type="text/javascript"></script>
<!-- End Google Map JavaScript -->
shorter version of JavaScript Code 较短版本的JavaScript代码
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(ShowPosition);
}
else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
function showError(error) {
switch (error.code) {
case error.PERMISSION_DENIED:
alert("User denied the request for Geolocation.");
break;
case error.POSITION_UNAVAILABLE:
alert("Location information is unavailable.");
break;
case error.TIMEOUT:
alert("The request to get user location timed out.");
break;
case error.UNKNOWN_ERROR:
alert("An unknown error occurred.");
break;
}
}
function ShowPosition(position) {
//begin rest call
$("#latitude").val(position.coords.latitude);
$("#longitude").val(position.coords.longitude);
$.ajax({
type: "GET",
cache: false,
async: false,
url: "http://www.dentalo.se/RestService/Dentalo.svc/Companies",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
map = new GMaps({
el: '#map',
lat: position.coords.latitude,
lng: position.coords.longitude,
zoom: 15,
zoomControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoomControlOpt: {
style: google.maps.ZoomControlStyle.SMALL,
position: google.maps.ControlPosition.RIGHT_TOP
},
panControl: true,
scrollwheel: true
});
map.addMarker({
lat: position.coords.latitude,
lng: position.coords.longitude,
title: 'Min position',
icon: 'http://www.dentalo.se/assets/img/map/user_x64.png'
});
$.each(data, function (index, item) {
map.addMarker({
lat: item.Latitude ,
lng: item.Longitude ,
title: item.Address ,
icon: GetMarkerImage(item.Status),
infoWindow: {
content: '<div style="width: 300px"><h4>' + item.Name + '</h4><br /><p>' + item.Address + ', ' + item.County.Name + '</p><div class="four columns alpha"><a class="btn blue ' + SetDisplayClass(item.Status) + '" href="booking/' + item.CompanyId + '" ><i class="m-icon-swapright m-icon-white"></i> Boka</a> <a href="#" onClick="showPopUp('' + item.CompanyId +'');return false;" class="btn default">Information</a></div></div>',
}
})
});
},
error: function (msg, url, line) {
//alert('error trapped in error: function(msg, url, line)');
alert('msg = ' + msg + ', url = ' + url + ', line = ' + line);
}
});
Many thanks. 非常感谢。
* Begin Edit * *开始编辑*
I have solved the problem. 我已经解决了问题。 It was a Url issue. 这是一个网址问题。 In the ajax call to the rest service you should not specify the complete Url. 在对其余服务的ajax调用中,您不应指定完整的Url。
You should do it like this 你应该这样
I change this line 我改变这条线
url: " http://www.dentalo.se/RestService/Dentalo.svc/Companies ", 网址:“ http://www.dentalo.se/RestService/Dentalo.svc/Companies ”,
To 至
url: "RestService/Dentalo.svc/Companies", 网址:“ RestService / Dentalo.svc / Companies”,
$.ajax({
type: "GET",
cache: false,
async: false,
url: "RestService/Dentalo.svc/Companies",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
map = new GMaps({
el: '#map',
lat: position.coords.latitude,
lng: position.coords.longitude,
zoom: 15,
zoomControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoomControlOpt: {
style: google.maps.ZoomControlStyle.SMALL,
position: google.maps.ControlPosition.RIGHT_TOP
},
panControl: true,
scrollwheel: true
});
map.addMarker({
lat: position.coords.latitude,
lng: position.coords.longitude,
title: 'Min position',
icon: 'http://www.dentalo.se/assets/img/map/user_x64.png'
});
$.each(data, function (index, item) {
map.addMarker({
lat: item.Latitude ,
lng: item.Longitude ,
title: item.Address ,
icon: GetMarkerImage(item.Status),
infoWindow: {
content: '<div style="width: 300px"><h4>' + item.Name + '</h4><br /><p>' + item.Address + ', ' + item.County.Name + '</p><div class="four columns alpha"><a class="btn blue ' + SetDisplayClass(item.Status) + '" href="booking/' + item.CompanyId + '" ><i class="m-icon-swapright m-icon-white"></i> Boka</a> <a href="#" onClick="showPopUp('' + item.CompanyId +'');return false;" class="btn default">Information</a></div></div>',
}
})
});
},
error: function (msg, url, line) {
//alert('error trapped in error: function(msg, url, line)');
alert('msg = ' + msg + ', url = ' + url + ', line = ' + line);
}
});
* End Edit * *结束编辑*
the getCurrentPosition
method has an infinite time out by default. 默认情况下, getCurrentPosition
方法具有无限超时。 Try this: 尝试这个:
navigator.geolocation.getCurrentPosition(ShowPosition, showError, {timeout:2000})
There are two other options you can set in this object: enableHighAccuracy
and maximumAge
您可以在此对象中设置其他两个选项: enableHighAccuracy
和maximumAge
Check out: http://diveintohtml5.info/geolocation.html for more info. 退房: http : //diveintohtml5.info/geolocation.html了解更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.