昨天看到一个问题,要求在使用 jquery 封装的 ajax 的情况下,且不在业务逻辑里面进行输出。在异步请求发起前输出异步请求内容,包括 asyncType,body,cache 等. import $ from 'jquery'; import beforeAsyncSend from './beforeAsyncSend'; $.ajax(url,{ type: "POST", url: "/test", data: JSON,stringify({ name:'Jean', age:18 }), async: false }) beforAsyncSend(beforeSend){ console.log(beforeSend); } //输出{'asyncType':'POST','body':'{"name":"Jeam","age":"18"}','cache':'true'}
有一点思路不知道对不对,在$.ajax.prototype 拓展一个函数?