S
S
skarietsky2017-03-10 14:01:41
JavaScript
skarietsky, 2017-03-10 14:01:41

Where and how is it better to make a request to the server or is it not needed?

Task: News is displayed on the main page. It is necessary, depending on the time zone (time) of the user, to adjust the news time values. yii project.
If you write ajax in the form, it means that the request will go twice, and this is bad.
I would not want to redraw ready-made news with js, because on the server to correct the time - a couple of lines, and on the client you have to recalculate a lot + there are widgets on the page.
What is the best way to do this and where?

News format:
Date
Time - news
Time - news
Number
Time - news
Time - news

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Falseclock, 2017-03-10
@Falseclock

1. Wrap the date string, for example, in <span>
2. inside the span, make the data-date attribute

<span data-date="тут метка времени из базы"></span>

3. When loading the page, read all spans that have the data-date attribute and insert the value according to the time on the user's computer.
Just keep in mind that it is better to store data in the database in UTC.

S
Stalker_RED, 2017-03-10
@Stalker_RED

Additional overgrowth is not needed. Why do you not like the timezone definition on the client and what is the problem with widgets?
https://jsfiddle.net/j5veLew4/
Format the output - a couple more lines. If it's difficult - you can use moment.js

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question