zoukankan      html  css  js  c++  java
  • jQuery ajax在IE下处理url=""时的一个不兼容

    小猪之前写了这么个代码:

    AJAX = function (data, url, beforesendfn, onsuccessfn, onerrorfn, oncomplete) {
           $.ajax({
                type: "POST",
                url:url
                cache: false,
                data: JSON.stringify(data),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                beforeSend: beforesendfn,
                success: onsuccessfn,
                error: onerrorfn,
                complete: oncomplete
            });
    }

    这段代码实际上是没有什么问题的。

    但是在调用代码的时候小猪使用了的参数

    var action = url == undefined ? "" : url;

    这样在没有定义url的情况下url转换成“”。本意是想Post到当前页面地址。

    在Chrome下和FireFox下都是没问题的,但是在IE下却不能post到对应地址。

    所以为了兼容IE 小猪只好写了下述可怜的代码

    AJAX = function (data, url, beforesendfn, onsuccessfn, onerrorfn, oncomplete) {
        if (url == undefined || url == "") {
            $.ajax({
                type: "POST",
                cache: false,
                data: JSON.stringify(data),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                beforeSend: beforesendfn,
                success: onsuccessfn,
                error: onerrorfn,
                complete: oncomplete
            });
        } else {
            $.ajax({
                type: "POST",
                url:url,
                cache: false,
                data: JSON.stringify(data),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                beforeSend: beforesendfn,
                success: onsuccessfn,
                error: onerrorfn,
                complete: oncomplete
            });
        }
    }
  • 相关阅读:
    HDU 1175 连连看 (DFS+剪枝)
    CF702F T-Shirts
    UVA12538 Version Controlled IDE
    P2605 [ZJOI2010]基站选址
    P3835 【模板】可持久化平衡树
    CF915E Physical Education Lessons
    P3701 「伪模板」主席树
    P1198 [JSOI2008]最大数
    P3466 [POI2008]KLO-Building blocks
    P3919 【模板】可持久化数组(可持久化线段树/平衡树)
  • 原文地址:https://www.cnblogs.com/smallerpig/p/3646121.html
Copyright © 2011-2022 走看看