简体   繁体   English

jQuery Rest Service响应仅适用于Chrome浏览器,不适用于IE或FF

[英]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(&apos;' + item.CompanyId +'&apos;);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(&apos;' + item.CompanyId +'&apos;);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 您可以在此对象中设置其他两个选项: enableHighAccuracymaximumAge

Check out: http://diveintohtml5.info/geolocation.html for more info. 退房: http : //diveintohtml5.info/geolocation.html了解更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JavaScript浏览器问题在FF中有效,但在IE和Chrome中无效 - javascript browser problem works in FF but not in IE and Chrome JS / jQuery代码适用于Chrome,但不适用于IE / FF - JS/jQuery code works in chrome but not IE/FF 用于自动登录的jQuery .submit适用于FF,Chrome ...而不是IE - jQuery .submit for autologin works in FF,Chrome… not IE 简单的GET rest服务只能在IE(或Postman)中使用,而不能在Chrome中使用,而不能在Firefox中使用 - Simple GET rest service works in IE only ( or Postman ) , but not in Chrome , not in Firefox JQuery - Chrome 中的背景图像旋转问题(仅在 F5 刷新后有效)。 在 FF、Safari、IE 中没有问题 - JQuery - Background image rotation issues in Chrome (works only after F5 refresh). No problems in FF, Safari, IE Javascript在Chrome上有效,但在IE或FF上无效 - Javascript works on Chrome, but no on IE or FF 脚本在Chrome中有效,但在IE或FF中不起作用 - Script works in Chrome but not in IE or FF jQuery 隐藏仅适用于 Chrome Mac 和 IE,不适用于 Chrome PC 或 FF - jQuery hide only working on Chrome Mac and IE, not Chrome PC or FF JavaScript适用于IE + Chrome,但不适用于FF - JavaScript works in IE + Chrome but not FF IE9 / FF / Chrome的Javascript / JQuery浏览器测试框架 - Javascript/JQuery browser testing frame work for IE9/FF/Chrome
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM