简体   繁体   English

如何“刷新”单个页面的应用程序

[英]How to “refresh” a single page application

Suppose I have a single page application that makes AJAX requests to http://www.somesite.com/resources?lang=en . 假设我有一个单页应用程序,该应用程序向http://www.somesite.com/resources?lang=en发出AJAX请求。

Now, let's say that my application has a special variable for the request's languages, that is, if the variable's value is en , then the AJAX request will send a query param lang=en . 现在,假设我的应用程序有一个针对请求语言的特殊变量,即,如果变量的值为en ,则AJAX请求将发送查询参数lang=en

For now, the two possible values are en and es . 目前,两个可能的值为enes

This variable's value can be changed dynamically by the user (clicking a button). 用户可以动态更改此变量的值(单击按钮)。

So, if we are using the application with language = en , then the application will send the lang=en query parameter. 因此,如果我们使用language = en的应用程序,则该应用程序将发送lang=en查询参数。 If the user changes the language to es , then I want the application to resend all the AJAX requests but now with lang=es query parameter. 如果用户将语言更改为es ,那么我希望应用程序重新发送所有AJAX请求,但现在使用lang=es查询参数。

It would be like refreshing the website, but asynchronously via AJAX requests. 这就像刷新网站,但通过AJAX请求异步进行。

I have been thinking this yesterday and I can't find a way to handle this logic in an AngularJS application. 我昨天一直在想这个问题,但找不到在AngularJS应用程序中处理此逻辑的方法。

I'm not an expert in AngularJS, but I understand the concepts of modules, directives, services and controllers. 我不是AngularJS的专家,但是我了解模块,指令,服务和控制器的概念。

What would be the best approach to handle this scenario? 处理这种情况的最佳方法是什么? That is, I would like to avoid having to call each AJAX request manually, I'd rather create an automatic way of doing this. 也就是说,我希望避免手动调用每个AJAX请求,而宁愿创建一种自动的方式来执行此操作。

Have you tried any AngularJS plugins? 您是否尝试过任何AngularJS插件? First that comes to mind is Angular translate 首先想到的是Angular翻译

Best way to concate the ajax url with lang parameter and request again. 将ajax url与lang参数连接并再次请求的最佳方法。

So you will get all new data base on lang parameter, won't forget to handle cache before requesting the ajax call. 因此,您将获得所有基于lang参数的新数据库,不会忘记在请求ajax调用之前处理缓存。

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

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