简体   繁体   English

重写XMLHttpRequest并模拟响应

[英]Override XMLHttpRequest and emulate response

Would it be possible to override XMLHttpRequest and emulate response from a callback ? 是否可以重写XMLHttpRequest并模拟回调的响应?

Something like : 就像是 :

 window.XMLHttpRequest.prototype.open = function() { var url = arguments[1]; if (url === 'someUrl' && isOnline === false){ //Return a fake reponse to the request... } ... } 

It would be realy nice to do this in my phonegap app, so if the user is offline I could retrieve the response from my local sqlite db. 在我的phonegap应用中执行此操作确实非常好,因此,如果用户处于脱机状态,则可以从本地sqlite数据库中检索响应。

解决的办法是使用嘲笑插件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM