写个H5页面带转义符,能在postman以string类型发送
时间: 2023-11-10 14:25:17 浏览: 41
<!DOCTYPE html>
<html>
<head>
<title>转义符测试</title>
</head>
<body>
<h1>转义符测试</h1>
<p>以下是一些常见的转义符:</p>
<ul>
<li>< :小于号</li>
<li>> :大于号</li>
<li>& :&符号</li>
<li>" :双引号</li>
<li>' :单引号</li>
<li>\ :反斜杠</li>
</ul>
<form>
<label for="input">在此输入需要转义的字符串:</label>
<input type="text" id="input">
<button type="button" onclick="sendData()">发送到postman</button>
</form>
<script>
function sendData() {
const input = document.getElementById('input').value;
const escaped = escape(input);
const xhr = new XMLHttpRequest();
xhr.open("POST", "http://localhost:3000/data", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
const data = `input=${escaped}`;
xhr.send(data);
}
</script>
</body>
</html>