简体   繁体   中英

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 .

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 .

For now, the two possible values are en and es .

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. 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.

It would be like refreshing the website, but asynchronously via AJAX requests.

I have been thinking this yesterday and I can't find a way to handle this logic in an AngularJS application.

I'm not an expert in AngularJS, but I understand the concepts of modules, directives, services and controllers.

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.

Have you tried any AngularJS plugins? First that comes to mind is Angular translate

Best way to concate the ajax url with lang parameter and request again.

So you will get all new data base on lang parameter, won't forget to handle cache before requesting the ajax call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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