【发布时间】:2017-07-19 11:09:42
【问题描述】:
我有一个 XHR 对象。当 send() 方法被触发时,我想在没有服务器、任何网络操作的情况下提供响应。
var origSend = xhr.send;
xhr.send = function () {
waitForFile(xhr, url).then(responseData=>{
//ı wantto that responseData , send to xhr response
//this responseData comes from anywhere(webrtc,fetch,filesystem,localstorage,......)
}); // side-effect
FileRequests.next({url: url})
//origSend.call(xhr, arguments) //I don't want to call original send method
}
//等待响应的代码
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status==200) {
console.log(xhr.responseText);
}
}
【问题讨论】: