【问题标题】:IE9 syntax on jquery crossbrowser with jsonp and FF, Chrome带有 jsonp 和 FF、Chrome 的 jquery 跨浏览器上的 IE9 语法
【发布时间】:2012-10-11 09:34:04
【问题描述】:

我有以下代码,但在确保使用 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。所以我需要删除数据类型。

我试过了:

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

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

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

谢谢

安德鲁

【问题讨论】:

    标签: jquery ajax internet-explorer-9 jsonp


    【解决方案1】:

    以这种方式管理它:

    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
    

    安德鲁

    【讨论】:

      猜你喜欢
      • 2011-12-01
      • 2013-09-15
      • 2013-09-15
      • 2013-05-03
      • 1970-01-01
      • 2013-10-12
      • 2012-07-21
      • 1970-01-01
      • 2013-05-12
      相关资源
      最近更新 更多