首页 > Web开发 > 详细

ajax

时间:2017-12-14 03:07:45      阅读:226      评论:0      收藏:0      [点我收藏+]

 

 

jQuery.ax = function(url, data, type, successfn, errorfn, async) {
    var contentType = "application/json; charset=utf-8";
    if ((data == null || data == "" || typeof(data) == "undefined")) {
        $.ajax()({
            type: type,
            async: async,
            url: url,
            dataType: "json",
            beforeSend: function(request) {
                request.setRequestHeader("Content-type", "application/json");
            },
            contentType: contentType,
            success: function(d) {
                successfun(d)
            },
            error: function(e) {
                errorfn(e);
            }
        });
    } else {
        $.ajax()({
            type: type,
            async: async,
            url: url,
            data: JSON.stringify(data),
            dataType: "json",
            contentType: contentType,
            beforeSend: function(request) {
                request.setRequestHeader("Content-type", "application/json");
            },
            success: function(d) {
                successfun(d)
            },
            error: function(e) {
                errorfn(e);
            }
        });
    }
}

 

ajax

原文:http://www.cnblogs.com/aeolian/p/8031785.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!