单击 div 时有什么方法可以在 Node js 服务器中获取值

这是我的 EJS 文件


<!DOCTYPE html>

<html dir="ltr">

  <head>

    <meta charset="utf-8">

    <title>Sart Plug</title>

    <script src="http://code.jquery.com/jquery-3.5.1.js" integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script>

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">

    <link rel="stylesheet" href="/css/usrDashboard.css">

    <link rel="icon" href="/images/plugimg.png" type="image/x-icon" />

  </head>

  <body>

    <div class="container">

      <div class="header">

        <a href="#" class="logo">Select Device</a>

        <div class="header-right">

          <a href="/logout">Log Out</a>

        </div>

      </div>

      <div class="jumbotron" id="jumbo">

        <p><%=data.noResult%></p>

        <div class="row">

          <% for(var i=0; i < data.result.length; i++) { %>

            <div class="col-25">

              <a href="/plugDashboard">

                <p><img class="img-fluid" src="/images/plugimg.png" alt="Plug Image"></p>

                <p><h3><%= data.result[i].device_name %></h3></p>

                <p><h6><%= data.result[i].device_address %></h6></p>

              </a>

            </div>

          <% } %>

        </div>

      </div>

    </div>

  </body>

</html>


冉冉说
浏览 196回答 1
1回答

繁星淼淼

您可以添加新的GET快速路线,例如:router.get('/get_mac_info/:mac_id', function(req, res, next) {&nbsp; res.json({&nbsp; &nbsp; mac_id: 'test_id'&nbsp; });});之后只需添加ajax点击事件调用:$(function () {&nbsp; &nbsp; $(document).on('click', '.col-25', function (e) {&nbsp; &nbsp; &nbsp; &nbsp; $.get('/get_mac_info/' + mac_id, function(data){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('.print_container').text(data)&nbsp; &nbsp; &nbsp; &nbsp; })&nbsp; &nbsp; &nbsp; &nbsp; e.preventDefault();&nbsp; &nbsp; });});
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript