封装ajax,ajax封装,原生js
由于项目中需要在提交ajax前设置header信息,jquery的ajax实现不了,我们自己封装几个常用的ajax方法。
jQuery的ajax普通封装
| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | var ajaxFn = function(uri, data, cb) {   $.ajax({       url: uri,       type: 'POST',       dataType: 'json',       data: data,     })     .done(cb)     .fail(function() {       console.log("error");     })     .always(function() {       console.log("complete");     }); } |