阿贾克斯刷新使用EX preSS和jQuery的局部视图? [英] Ajax to refresh a partial view using express and JQuery?
问题描述
我想刷新使用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);
另请参见<一个href="http://stackoverflow.com/questions/6006672/node-js-ex$p$pss-how-to-get-partial-views-asynchronously/6083403#6083403">my回答这个类似的问题。
这篇关于阿贾克斯刷新使用EX preSS和jQuery的局部视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!