Can I use echo to pass php values to js?

Source: Internet
Author: User
Can I use echo to pass php values to js? For example, the question is that the value is transmitted in json format. because there are many records, it takes too much time to use echo.


Reply to discussion (solution)

Why does it take too much time to use echo?

Serialization or json encoding before echo;

Echo json_encode ($ array );

Because the database query results have a large number of records, it is too slow for the front-end to click query when it is sent to ajax.

Serialization or json encoding before echo;

Echo json_encode ($ array); $ result = mysqli_query ($ dbc, $ query );
$ Amount = mysqli_num_rows ($ result );
$ Jsonresults = array ();
While ($ row = mysqli_fetch_array ($ result )){
$ Jsonresults [] = $ row ;}

$ Jsonresult = json_encode ($ jsonresults );

Echo $ jsonresult;
This is my php code. it has been converted, but there are many records. It takes about two seconds to respond after the query (nearly 3000 array Records)

Have a question.
What is the execution time for LZ to input $ dbc in the MYSQL command line?
It may not be a PHP parsing problem. it may also be the time it takes to read data.

Have a question.
What is the execution time for LZ to input $ dbc in the MYSQL command line?
It is not necessarily a PHP parsing problem. it may also be that it took me the time to read the data. I tried echo $ jsonresult; first, I changed it to a comment, and then I used echo "a"; to display it to the front-end, at this time, the speed is much faster, and the previous reading has not changed.

3000 array records, 2 s is very fast. Does it take some time to convert 3000 array records to json?

3000 array records, 2 s is very fast. Does it take some time to convert 3000 array records to json? There should be a better way. I think some people have done it. The results of more than 10 thousand arrays will come out in an instant.

Echo "a"; to replace echo $ jsonresult; fast
It indicates that it is a problem at the front-end. of course, only echo "a"; there will be errors at the front-end.

Doesn't it take time to render 3000 * n html objects at the front end?

Echo "a"; to replace echo $ jsonresult; fast
It indicates that it is a problem at the front-end. of course, only echo "a"; there will be errors at the front-end.

Isn't it necessary to render 3000 * n html objects at the front end? is it possible because the front end needs to upload the previous result eval. I use echo ""; replace the comments with comments. it may be that eval is time-consuming and the moderator is huge. Is there a way to improve it?

Do you have to query 3000 records at a time? If not necessary, you can obtain them in batches based on user behavior.

You can consider batch loading, just like the waterfall stream.
3000 * n items of data will also have a scroll bar, that is, it is impossible to see all at once
First see first load, then see then load, this is the so-called "waterfall flow"

Paging. Too many browsers are stuck.

You can consider batch loading, just like the waterfall stream.
3000 * n items of data will also have a scroll bar, that is, it is impossible to see all at once
First, we see loading first, and then loading after we see it. this is the so-called "Waterfall Stream". I use ajax. after clicking the query, each time a record is displayed, a record is an html table, next, you don't need to refresh the page on the previous page. at this time, the switching record will be very fast and the time will be negligible, that is, the query will wait for a while after the start point. is this suitable for batch loading?

Batch loading is no problem. how can I get all the data to the front-end? The traffic is huge. isn't your server dead yet?

Thank you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.