本文介绍了使用 Node 在 res.render() 中发送请求后页面内容未加载/显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有服务器文件,即 node_app.js,客户端文件 login.php、group.php 和 display_group_details.php.

I am having server file i.e.node_app.js , client files login.php,group.php and display_group_details.php.

使用 Jade(查看模板引擎)登录页面重定向到 group.php 后,在组页面上,我有一个包含组列表的表格,其中包含列 id、group_name、描述、容量和带有显示详细信息"按钮的最后一列.

After login using Jade (view template engine) login page redirected to group.php, here on group page, I have table with group list having columns id,group_name,description,capacity and last column with 'show detail' button.

当我单击显示详细信息"按钮时,我想打开包含所选组详细信息的弹出窗口.根据我打开的代码弹出窗口,URL 显示在地址栏中,但最初没有显示页面内容,刷新页面时显示.

When I click on 'show detail' button I want to open popup with details of selected group. As per my code popup get opened, URL is showing in address bar but no page content displayed initially, it displayed when I refresh the page.

它必须在刷新后打开带有页面内容的弹出窗口.

It must open popup with page content not after refresh.

这是我的代码:

app.get('/joined_group', function (req, res) {
selected_group_id = req.query.grpid;

var qry= "SELECT * FROM `groups`  where `group_id` = "+selected_group_id;
    con.query(qry, function(err, result, fields)
    {
            res.render('group_details');//name of jade file
    });
});

在名为 group_details 的 Jade 文件中,我有如下代码:

In Jade file named group_details i have code like :

include details.php

我做错了什么或缺少什么?

What I am doing wrong or what things are missing?

注意:以前,当我不使用 xampp 运行此应用程序代码时,用于单击按钮,例如:

NOTE: Previously when I am not using xampp to run this application code was for button click like :

<button class="btn btn-primary"  onclick="window.open('/joined_group?grpid=1','name','width=1200,height=600','_blank')">
                                        Join</button>

现在我使用的是 xampp,因为 Xampp (Apache) 和 Node http 服务器的端口不同,代码就像

Now I am using xampp so as ports are different for Xampp (Apache) and Node http server, code is like

<button class="btn btn-primary"  onclick="window.open('localhost:8087/joined_group?grpid=<?php echo $group['group_id'];?>','name','width=1200,height=600','_blank')">
                                        Join</button>

使用这个弹出窗口打开但空白,刷新后显示内容,但不应该那样.

Using this popup get opened but blank, it displays content after refresh, but it should not be like that.

注意:请看看我编辑过的代码,单击按钮后的 node_app.js(如上文所示,但有一些更改,将参数与文件一起发送)

NOTE: please have a look on code I have edited,node_app.js after button click (as shown earlier above but with some changes , send parameters along with file as )

  res.render('group_details',{grp_id:selected_group_id,grp_name:result[0].grp_name,loggeduser:'test'});

和 group_details.jade :

and group_details.jade :

   script(type='text/javascript')
  | var grpid="#{grpid}"
  | var grp_name="#{grp_name}"
  | var loggeduser="#{loggeduser}"
  include details.php

在单击按钮后加载页面时,我是否在 jade 文件或节点 node_app.js 文件中做错了什么或遗漏了一些?

am I doing something wrong or missing some in jade file or node node_app.js file while loading page after button click?

推荐答案

我终于知道如果使用 xampp 和 node.js 服务器该怎么办了.

Hi Finally i got what to be done if using xampp as well as node.js server.

我已经关注了 T.Todua" 帖子的回答:如何在Xampp localhost上安装nodejs

I have followed answer of "T.Todua" of post : How to install nodejs on Xampp localhost

它现在可以工作了.谢谢!

its working now. Thanks!

这篇关于使用 Node 在 res.render() 中发送请求后页面内容未加载/显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 11:41