1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| window.jQuery = function(nodeOrSelector){ let nodes = {} nodes.addClass = function(){} nodes.html = function(){} return nodes } window.$ = window.jQuery
window.jQuery.ajax = function({url, method, body, successFn, failFn, headers}){ let request = new XMLHttpRequest() request.open(method, url) for(let key in headers) { let value = headers[key] request.setRequestHeader(key, value) } request.onreadystatechange = ()=>{ if(request.readyState === 4){ if(request.status >= 200 && request.status < 300){ successFn.call(undefined, request.responseText) }else if(request.status >= 400){ failFn.call(undefined, request) } } } request.send(body) }
function f1(responseText){} function f2(responseText){}
myButton.addEventListener('click', (e)=>{ window.jQuery.ajax({ url: '/frank', method: 'get', headers: { 'content-type':'application/x-www-form-urlencoded', 'frank': '18' }, successFn: (x)=>{ f1.call(undefined,x) f2.call(undefined,x) }, failFn: (x)=>{ console.log(x) console.log(x.status) console.log(x.responseText) } }) })
|