在jQuery中使用类似于res渲染的东西

时间:2018-12-20 15:24:52

标签: jquery node.js express

当我加载我的应用程序时,我使用这样的路由系统:

 router.get('/home', verifyAuth, function (req, res) {
  axios.get('http://localhost:3000/api/posts')
    .then(resposta => {  
      res.render('home', { info: resposta.data })
    })
    .catch(erro => { 
      res.render('error', { error: erro, message: 'Error' })
    })

});

但是在我的html中,我有一些触发此功能的按钮

  var array= new Array()
function myFunc(test){ 
    array.push(test)  
    $.ajax({
        url: "http://localhost:3000/api/posts/filter/",
        contentType:"application/json",
        type: "POST",
        data: JSON.stringify({myArray: array}),
        dataType: "json",
        success: function(data){ 
            //res.render('home', { info: data })
         }
      });   
}

我该如何做像ajax的success中的内容?

0 个答案:

没有答案