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
            });
        }
    }
  • 相关阅读:
    python脚本
    python引用,浅拷贝,深拷贝
    postgresql MVCC详解
    sql排它锁
    sqlalchemy使用
    ASP.Net MVC开发基础学习笔记(7):数据查询页面
    js timestamp与datetime之间的相互转换
    聊聊iOS中TCP / UDP 协议
    IOS -执行时 (消息传递 )
    Java对象的序列化和反序列化
  • 原文地址:https://www.cnblogs.com/smallerpig/p/3646121.html
Copyright © 2011-2022 走看看