Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 加载返回的HTML文件_Javascript_Html_Jquery_Express - Fatal编程技术网

Javascript 加载返回的HTML文件

Javascript 加载返回的HTML文件,javascript,html,jquery,express,Javascript,Html,Jquery,Express,我有一个HTML按钮,点击后,它会发送一个get请求来获取HTML文件,我想加载get HTML文件来替换当前的HTML文件 前端代码如下所示: document.getElementById("single_user_button").onclick = function() { $.get('/profile', {token: idToken}, (res) => { console.log(res);

我有一个HTML按钮,点击后,它会发送一个get请求来获取HTML文件,我想加载get HTML文件来替换当前的HTML文件

前端代码如下所示:

        document.getElementById("single_user_button").onclick = function() {
          $.get('/profile', {token: idToken}, (res) => {
            console.log(res);
          })
        }
我正在使用快速路由器来处理这个问题:

router.get("/profile", (req, res) => {
  res.sendFile(path.join(__dirname, "../public/html/main/ll_profile.html"));
});

我可以在
res
变量中看到
ll_profile.html
。但是我不知道如何加载它来替换当前的HTML页面。我尝试了JQuery
.load()
,但那是为了加载到ID中。我应该怎么做?

你的意思是
window.location.href=res
.load()
在你之前选择的任何元素上运行,不需要用ID来标识。例如
$('body').load(“…”)
会将html加载到
元素中,而您可以使用.html(),您的意思是
window.location.href=res
.load()
在您之前选择的任何元素上运行,不需要由id标识。例如
$('body')。load('…'))
会将html加载到
元素中,而您可以使用.html()