Ajax使用express和JQuery刷新局部视图? [英] Ajax to refresh a partial view using express and JQuery?

查看:121
本文介绍了Ajax使用express和JQuery刷新局部视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用ajax刷新部分视图。
我想知道如何将新数据附加到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.

我有部分查看这个


  • 数据中的每个x
    li x.name

我使用!= partial('test',{data:data})传递数据

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

我想调用函数可以再次渲染部分视图,而无需重新加载页面。
并且不做append(...);
任何想法?
或其他方法来做...

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...

推荐答案

首先,添加一个路由, p>

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});
});

然后使用jQuery加载新的HTML .get .ajax 调用 / mypartial

Then load the new HTML with a jQuery .get or .ajax call to /mypartial.

然后使用jQuery通过执行

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

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

另请参见我对这个类似问题的回答

这篇关于Ajax使用express和JQuery刷新局部视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆