简体   繁体   English

更改EJS变量而不刷新页面Nodejs

[英]change EJS varaibles without refreshing the page Nodejs

so I have this problem, Im trying to build a website in which people can give out links which I will then analyze using request-promise.js (so on the server side) . 所以我有这个问题,我试图建立一个网站,人们可以在其中给出链接,然后我将使用request-promise.js(在服务器端)进行分析。 This analysis will try to find embed videos in the given link. 此分析将尝试在给定的链接中找到嵌入的视频。 If present I want to make that emebed video appear in an iframe on my current page. 如果有的话,我想让该视频显示在当前页面的iframe中。

So for now Ive managed to get the embed the video, and render it in an EJS template variable , but this means that I have to use res.render('page', variables) and from my understanding that means reloading the page. 因此,到目前为止,我已经设法嵌入了视频,并将其呈现在EJS模板变量中,但这意味着我必须使用res.render('page',variables),并且根据我的理解,这意味着需要重新加载页面。

What I want to know is if there is a way to do that without reloading the page ? 我想知道的是,是否有一种方法可以不重新加载页面?

(my goal is to make the found video appear in a bootstrap modal div that appears after people gave the link and clicked on my upload button that trigers the scrapping of the given link) (我的目标是使找到的视频显示在引导模式的div中,该模式出现在人们给出链接并单击我的上传按钮(触发对给定链接的抓取操作)之后)

Thanks for your help 谢谢你的帮助

Pardon me if my question is unclear 如果我的问题不清楚,请原谅我

You can use an XMLHttpRequest to get the data from the server asynchronously and display/store them on the page without reloading the whole page. 您可以使用XMLHttpRequest异步地从服务器获取数据,并将其显示/存储在页面上,而无需重新加载整个页面。

var url = '/get-embed-video/'+link;
var xmlHttp = new XMLHttpRequest();

xmlHttp.onreadystatechange = function () {
    if (xmlHttp.readyState === 4) {
        // here get the response from the server
        // and display your data
    }
}
xmlHttp.open("GET", url, true); // false for synchronous request
xmlHttp.send(null);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM