0

我有以下代码,我在确保使用 IE 浏览器时使用它的一部分时遇到问题,并在使用任何其他浏览器时将其删除:

            $.ajax({
            url: 'http://mapit.mysociety.org/areas/'+ulo,
            type: 'GET',
            cache: false,
            crossDomain: true,
            dataType: 'jsonp',
        success: function(response) {

这在 IE9 中运行良好,因为我将 dataType 设置为 jsonp。但这不适用于 Chrome 或 FF。所以我需要删除dataType。

我试过这个:

<!--[IF IE]> dataType: 'jsonp', <![endif]-->

但它没有用。值得注意的是,它在 FF 或 Chrome 中不需要设置 dataType,因为它是 json。

进行这项工作的正确语法是什么?

谢谢

安德鲁

4

1 回答 1

0

以这种方式管理它:

var version = navigator.appName;
            if(version == 'Microsoft Internet Explorer') {
                var theType = 'jsonp';
            }
            $.support.cors = true;
            $.ajax({
                        url: 'http://mapit.mysociety.org/areas/'+ulo,
                        type: 'GET',
                        cache: false,
                        crossDomain: true,
                        dataType: theType,

            success: function(response) {
                    etc etc

安德鲁

于 2012-10-11T10:57:23.737 回答