码迷,mamicode.com
首页 > Web开发 > 详细

ajax

时间:2017-12-14 04:29:03      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:post   fun   style   var   tty   gif   body   str   erro   

 

 

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

标签:post   fun   style   var   tty   gif   body   str   erro   

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

(1)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!