Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
183 views
in Technique[技术] by (71.8m points)

javascript - 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.

question from:https://stackoverflow.com/questions/66064689/pass-more-than-one-data-array-to-the-view-using-res-render-on-nodejs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)
          });

          })

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...