The problem of garbled codes encountered when express res.render sends a page and submits an array of objects at the same time

backend code

data contains the result of the query, which is an array of objects

res.render ("search_result", {title:" query result page", data: result});

Front end code

the jade template engine is not used here, so the way to get it is <% >

of HTML.
var data = "<% = JSON.stringify (data)% >";
alert (data);

then the result is.

as shown in the figure, the obvious passed object array is parsed as a string, and all symbols in it are also integrated into escape characters

.

personal needs

as mentioned above, the personal requirement is to send the page and hand in the queried data at the same time, and then render dynamically. Therefore:

  1. if there is a more elegant solution that can meet the above requirements, I would appreciate your advice;
  2. I would also appreciate it if I could solve the above problem of passing an array of objects.

in addition, I am a Node rookie. I have only been self-taught for less than two months, and I have not finished my express documents yet, so I hope to give a relatively detailed solution. Thank you

.
Mar.14,2021

has been solved, but is not good at learning?
ejs template engine <% = code% >, ejs will automatically escape for us.
replace it with <% code% >

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eb7cab-48448.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eb7cab-48448.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?