S
S
Sasha Brahms2015-11-12 21:10:05
PHP
Sasha Brahms, 2015-11-12 21:10:05

Passing data from php to js?

I know, the most banal question, but still how to do everything right?
ajax is not an option, a page is generated = a request to the database, make ajax = 1 more request to the database, somehow it is not logical ...
or make 1 request and return it right there?
What do you think?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew, 2015-11-12
@R0dger

well, I don’t know, I pass it like this for angularJs

<script type="text/javascript" charset="utf-8">
    window.data = <?php echo CJSON::encode($data);?>;
</script>

Accordingly, in the Angular controller, the
rest is already ajax if necessary...

O
Oleg, 2015-11-12
@LastDreamer

Give out the data that can be rendered when the page is loaded immediately.
If, due to user actions, new data should appear on the page, but you don’t want to reload the page, add / update data on the page using ajax.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question