简体   繁体   中英

Pass more than one data array to the view using res.render on nodeJs

I have two selects in my view and I need to populate each one with a different array. How do I pass two different jons using res.render? I tried the way below, but it didn't work.

const result1  = {data1: "val1", data2: "val2"}
const result2  = {Otherdata1: "val1xx", Otherdata2: "val2vv"}

res.render('my-view', {array1: result1, array2: result2});

That way, the page is processing and never updates. If anyone can help me thank you.

if there is no errors, this page will successfully send to the browser but it won't rendered because the browser expect to receive an json content not an html page.

you can find the required page with the updated data if you to the page in the browser and clicked right click ==> then press inspect ==> then go to Network ==> then choose the requested page ==> then choose response

to make it visible on the screen you need to go to java script file of the front end and put an call back function with response which is the html page such like so

.then(res => {
     document.open()
     res.text().then(function(text) {

           document.write(text)
          });

          })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM