阿贾克斯刷新使用EX preSS和jQuery的局部视图?视图、局部、EX、阿贾克斯

由网友(虛僞の敷衍)分享简介:我想刷新使用AJAX的局部视图。我kwow如何将新的数据添加到HTML,但我想知道是否有一个更简单的方法来做到这一点。I would like to refresh a partial view using ajax.I kwow how to append the new data to the HTML, b...

我想刷新使用AJAX的局部视图。 我kwow如何将新的数据添加到HTML,但我想知道是否有一个更简单的方法来做到这一点。

I would like to refresh a partial view using ajax. I kwow how to append the new data to the HTML, but I would like to know if there is a simpler way to do it.

我有部分观点认为做到这一点

I have partial view that does this

在每个数据x 李x.name each x in data li x.name

我通过使用=局部数据('测试',{数据:数据})!

I pass the data using !=partial('test',{data:data})

我要调用一个函数来再次呈现局部视图无需重新加载页面.. 并没有做追加(...); 任何想法?? 或者其他的方式来做到这一点...

I want to call a function to render the partial view again without reloading the page.. and without doing append( ... ); Any Idea?? Or other way to do it...

推荐答案

首先,添加路由只是部分像

First, add a route for just the partial like

app.get('/mypartial', function (req, res) {
    //compute data here
    res.render('mypartial', {layout: false, data: data});
});

然后加载新的HTML有一个jQuery 。获得阿贾克斯致电 / mypartial

然后使用jQuery做替换父元素的HTML

Then use jQuery to replace the HTML of the parent element by doing

$('#idofparentelementofyourpartial').html(responseHTML);

另请参见my回答这个类似的问题。

阅读全文

相关推荐

最新文章