如何愚弄jqXHR永远成功 [英] how to fool jqXHR to succeed always

查看:35
本文介绍了如何愚弄jqXHR永远成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使jQuery的ajax调用始终返回,就像它们成功执行一样, 例如即使没有网络,我也会返回一些本地保存的数据

I'm trying to make jQuery's ajax calls always return as if they succeeded, e.g. even when I don't have network, I will return some locally saved data

有可能吗?

我尝试使用$ .ajaxPrefilter并调用jqXHR的成功函数, 但仍然无法像请求已完成一样进行操作:(

I tried using the $.ajaxPrefilter and calling the success function of the jqXHR, but still it won't behave as if the request has finished :(

谢谢!

推荐答案

嗯,快速更新:以上解决方案均无效.
为了解决这个问题,我最终要做的是用我的实现替换jQuery的ajax函数,该函数检查是否存在网络连接.
如果存在,我将请求代理回原始的ajax函数,否则,我将创建与ajax相同的返回结构并将其返回

Well, a quick update: non of the solutions above worked.
What I eventually had to do to walk around this problem, is replace jQuery's ajax function with my implementation, that checks if there is network connection.
if there is, I proxy the request back to the original ajax function, else, I create the same return structure as ajax's would and return it

同样,我不想回答自己的问题,尤其是当它不是真正的答案而是更多的解决方法时. 伤心的...

Again, I hate answering my own questions, especially when it's not really an answer but more of a workaround. sad...

这篇关于如何愚弄jqXHR永远成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆