简体   繁体   中英

re-render pug view with express

Basically what I wantto achieve is a searchable/filterable listview

so far I'm able to fetch some data from a database and have express with pug render me a page showing the results in a listview.

Now I want to add the functionality of filtering the displayed listview. Therefore on every keyup event within a textbox I make an AJAX post request to the server sending the query string from the textbox. So far everything works just fine, but when i try to "re-render" the page with the filtered resultset nothing happens in the browser.

My routes look like this:

var rechnungen;

router.get('/', function(req, res) {

    connection.query('SELECT * FROM rechnungen ', function(err, result) {
    rechnugen = result;
    res.render('rechnungen', {rechnungen: result});

});

router.post('/:query', function(req, res) {
    console.log("received ajax request");
    console.log("with query " + req.params.query);
    res.render('rechnungen', {rechnungen: {}});
});

initially the query statement fetches the data and res.render works just fine, when I make the AJAX call everything seems to work as well (the console log output matches my input) but regardless what i try to pass to the view (res.render) in the post route nothing happens.

Is it not possible to "re-render" a view or is there any other conceptional misstake I make?

thanks for your help

AJAX POST call is not a traditional HTTP call.

The rendered page sent from the server will come in the response object of success handler of your AJAX call.

So, either

  • replace whole HTML with the response HTML, or
  • make a traditional HTTP form POST, in that case the browser by-default renders the response of the server.

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