简体   繁体   English

/ dev / null用于http请求

[英]/dev/null for http requests

I've found myself writing a number of mockups of websites that make a lot of AJAX calls. 我发现自己编写了许多进行AJAX调用的网站模型。 I'm really just fiddling with how the sites look and don't have a server backing them. 我真的只是在摆弄这些网站的外观,而没有服务器来支持它们。 Is there a place I can direct the requests that will eat them, return success, but not actually have any content. 有没有地方我可以指导那些会吃掉它们,返回成功但实际上没有任何内容的请求。 In effect, I want the AJAX calls to succeed, but not actually have anything returned. 实际上,我希望AJAX调用成功,但实际上没有任何返回。

I view this as a sort of /dev/null for the internet. 我认为这是Internet的一种/dev/null

只需创建一个空文件,然后使用相对路径请求该文件。

检出mockjax ,以及Google的其他AJAX模拟系统。

It depends how you do the AJAX calls. 这取决于您如何进行AJAX调用。 In my case I have a function called doAjaxCall which takes a callback function as argument (executed when the Ajax call returns). 在我的情况下,我有一个名为doAjaxCall的函数,该函数以回调函数作为参数(在Ajax调用返回时执行)。 For some unit tests I overwrite this function to just do a window.setTimeout() (calling the callback function after the timeout). 对于某些单元测试,我将覆盖此函数以仅执行window.setTimeout()(在超时后调用回调函数)。

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

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