简体   繁体   中英

Invoke a web service form JQuery: doesn't work in IE (JQMIGRATE: jQuery.browser is deprecated ??)

I'm a newbie in Ajax and JQuery but I need to invoke a web service in my little web application HTML/Javascript based.

All works fine using Firefox or Chrome but nothing happens using IE (I'm using IE 9 now ...).

Here you are the code

if ($.browser.msie && window.XDomainRequest) {
            if (window.XDomainRequest) {
                var query = 'http://wms.pcn.minambiente.it/ogc?map=/ms_ogc/wfs/Numeri_Civici_2012.map&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=IN.NUMERICIVICI.2012&SRSNAME=EPSG:4326&bbox=7.70,44.80,7.75,44.85&outputFormat=GML2';
                var xdr = new XDomainRequest();
                if (xdr) {
                    xdr.onload = function () {
                        alert("OK");
                    }
                    xdr.onerror = function () { 
                        alert("KO");
                    }
                    xdr.open('GET', query);
                    xdr.send();
                }
            }
        }
        else {
            var query = 'http://wms.pcn.minambiente.it/ogc?map=/ms_ogc/wfs/Numeri_Civici_2012.map&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=IN.NUMERICIVICI.2012&SRSNAME=EPSG:4326&bbox=7.70,44.80,7.75,44.85&outputFormat=GML2';
            $.ajax({
                type: "GET",
                url: query,
                dataType: "text",
                crossDomain: true,
                success: function (data1) {
                      alert("OK");
                      alert(data1)
                },
                error: function (response, textStatus, errorThrown) {
                    alert("KO");
                    alert(errorThrown);
                }
            });
        }

I tried to synthesize in a jsfiddle so you can try if you want.

When I try to execute in IE the browser console tell me that ...

JQMIGRATE: jQuery.browser is deprecated

How can I modify my code?

Thank you all in advance, any suggestion or wokaround will be appreciated!!!

Cesare

The $.browser function is, indeed, deprecated . If you want to detect IE, use this instead:

var browser = navigator.userAgent.toLowerCase(),
isIE = (browser.indexOf("msie")>-1 || browser.indexOf("trident")>-1);
if (isIE && window.XDomainRequest) {
  //the rest of your code
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM