<!DOCTYPE html> <html> <head> <title>查询和删除功能</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> </head> <body> <h1>查询和删除</h1> <form> <label for="queryInput">查询:</label> <input type="text" id="queryInput" name="queryInput"> <button onclick="query()">查询</button> </form> <form> <label for="deleteInput">删除:</label> <input type="text" id="deleteInput" name="deleteInput"> <button onclick="deleteItem()">删除</button> </form> <div id="result"></div> <script src="script.js"></script> </body> </html> ``` script.js: ```javascript function query() { var queryValue = document.getElementById("queryInput").value; $.ajax({ url: "/query", method: "GET", data: { query: queryValue }, success: function(response) { document.getElementById("result").innerText = response; }, error: function(xhr, status, error) { console.error(error); } }); } function deleteItem() { var deleteValue = document.getElementById("deleteInput").value; $.ajax({ url: "/delete", method: "DELETE", data: { delete: deleteValue }, success: function(response) { document.getElementById("result").innerText = response; }, error: function(xhr, status, error) { console.error(error); } }); } ``` server.js: ```javascript const express = require('express'); const bodyParser = require('body-parser'); const app = express(); app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); app.get('/query', (req, res) => { const queryValue = req.query.query; const result = `查询成功,结果为:${queryValue}`; res.send(result); }); app.delete('/delete', (req, res) => { const deleteValue = req.body.delete; const result = `删除成功:${deleteValue}`;
时间: 2024-04-21 07:23:47 浏览: 124
这段代码是一个简单的查询和删除功能的前端和后端实现。前端部分是一个HTML页面,包含两个表单:一个用于查询,一个用于删除。点击查询按钮时,会调用`query()`函数发送AJAX请求到服务器的`/query`路由,并将查询的值作为参数传递。点击删除按钮时,会调用`deleteItem()`函数发送AJAX请求到服务器的`/delete`路由,并将删除的值作为参数传递。
后端部分是一个Express应用,监听两个路由:`/query`和`/delete`。当收到`/query`路由的GET请求时,会获取查询的值并返回一个包含查询结果的响应。当收到`/delete`路由的DELETE请求时,会获取删除的值并返回一个包含删除成功信息的响应。
这段代码使用了jQuery库来简化AJAX请求的操作。
相关问题
<!DOCTYPE html></!DOCTYPE> <html> <head> <title>绿叶学习网</title> </head> <body> <p>绿叶学习网</p> </body> </html>哪里错了
在给出的HTML代码中,有两个地方出现了错误:
1. 第一行的`<!DOCTYPE html></!DOCTYPE>`是错误的。正确的写法是`<!DOCTYPE html>`,用于声明文档类型为HTML。
2. 第二行的`</!DOCTYPE>`也是错误的。正确的写法是`</html>`,用于闭合HTML标签。
修正后的代码如下:
```html
<!DOCTYPE html>
<html>
<head>
<title>绿叶学习网</title>
</head>
<body>
<p>绿叶学习网</p>
</body>
</html>
```
帮我翻译代码:<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <title>炫酷感科技感旋转vuejs特效</title> <script src="vue.js"></script> </head> <body> <div id="app"></div> <script type="module"> import CodePenVueComponent from "./script.js"; new Vue(CodePenVueComponent).$mount('#app'); </script> </body> </html>
这是一个 HTML 页面的代码。以下是代码的翻译:
```
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>炫酷感科技感旋转vuejs特效</title>
<script src="vue.js"></script>
</head>
<body>
<div id="app"></div>
<script type="module">
import CodePenVueComponent from "./script.js";
new Vue(CodePenVueComponent).$mount('#app');
</script>
</body>
</html>
```
注释:
- `<!DOCTYPE html>`:声明这是一个 HTML 页面。
- `<html lang="en">`:指定页面的语言为英语。
- `<head>`:页面头部,用于包含一些元数据(如标题、样式表和脚本等)。
- `<meta charset="UTF-8">`:指定页面的字符编码为 UTF-8。
- `<title>炫酷感科技感旋转vuejs特效</title>`:页面标题。
- `<script src="vue.js"></script>`:引入 Vue.js 库,以便在页面中使用 Vue.js 框架。
- `<body>`:页面主体,用于包含网页的内容。
- `<div id="app"></div>`:一个空的 `<div>` 元素,将作为 Vue.js 应用程序的容器。
- `<script type="module">...</script>`:在这个 `<script>` 标签中,我们通过 `import` 关键字引入了一个名为 `CodePenVueComponent` 的组件,并将其传递给 `new Vue()` 构造函数,最后调用 `$mount()` 方法将应用程序挂载到 ID 为 `app` 的 `<div>` 元素上。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044937.png)
![-](https://img-home.csdnimg.cn/images/20241231044937.png)
![-](https://img-home.csdnimg.cn/images/20241231044937.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)