Accessing passed EJS variable in Javascript file

前端 未结 5 885
轻奢々
轻奢々 2020-12-05 12:05

RESTful routes js file:

// index route - show all todos
router.get(\"/\", middleware.isLoggedIn,function(req,res) {
  Todo.find({ \"author.id\" : req.user._i         


        
5条回答
  •  天命终不由人
    2020-12-05 13:08

    By formatting the html printing of the JSON you get from the server and using javascript (my case jQuery) to retrieve that text, store it, and remove it from the html :)

    EJS:

    
    

    JavaScript:

    var variableJSON = JSON.parse($('#variableJSON').text());
    $('#variableJSON').remove();
    

提交回复
热议问题