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); } }); } }