0

I am trying to pass array of objects from backend to front end.

app.js

       router.post('/submits',urlencodedParser,function(req,res)
         {
          //getLocation function returns an array of objects
           getLocation(req.body.latval,req.body.longval)       
           res.redirect('./table');
          });
      router.get('/table',function(req,res)
        { 
          res.render("table");
         });

table.js (front end)

window.onload= table();
function table(array)
{
    var table = document.getElementById("table");

    for(var i = 0;i<table.rows.length;i++)
    {
      for(j=0;j<table.rows[i].cells.length;j++)
      {
        table.rows[i].cells[j].innerHTML = array[i][j];
      }
    }

  });

So I am trying to send the array as a parameter to the function in table.js. How can I do it?

3
  • Possible duplicate of Passing array from NodeJS server to client? Commented Oct 11, 2018 at 19:58
  • First you need to load it with http get, use $.ajax. Commented Oct 11, 2018 at 19:59
  • I would post the answer, but you should learn it yourself :) Commented Oct 11, 2018 at 20:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.