简体   繁体   中英

Passing an array from node.js to another array in an HTML page

app.post('/reserveWorkspace', function(req, res) {

        connection.query( 'SELECT DeskName FROM desks WHERE stat = ?',["Booked"], function(err,     rows){
        if(err)
        {
            throw err;
        }
        else
        {
          try
           {

              res.render('workspaces.html',{myArray: rows.DeskName});
              for(i=0;i<rows.length;i++)
              {        
                console.log(rows[i].DeskName);
              }}
          catch (e)
           {
            console.log(e);
           }
        }
});

I have the above node.js code, what i want to accomplish is that i want to pass all the selected rows from my DB table to the "myArray" and pass the array to another javascript array in an HTML page which is workspaces.html . i can successfully display them on the console, but i cant successfully pass them to the html page..... Any suggestions?

HERE IS THE HTML CODE:

 <script type="text/javascript">
   function myFunction(){
      var bookedSeatss =  "<%= myArray%>";
      document.getElementById("test2").value = bookedSeatss[0];
    }
 </script>

尝试对它们进行分类:

res.render('workspaces.html',{myArray: JSON.stringify(rows.DeskName)});

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