Matias Cicero
Matias Cicero

Reputation: 26281

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.

Upvotes: 0

Views: 2957

Answers (2)

Pavelloz
Pavelloz

Reputation: 569

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

Upvotes: 1

asimshahiddIT
asimshahiddIT

Reputation: 330

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.

Upvotes: 0

Related Questions