为什么不显示消息
Why isn't this displaying a message?
我正在编写一个简单的HTML表单来测试我构建的PHP数据库应用程序。它以可验证的方式将项目添加到数据库,但它拒绝创建显示消息。谁能解释一下发生了什么?
这是我的代码:
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8"/>
<style>
textarea {
width: 90%;
height: 300px;
border-radius: 12px;
}
form {
max-width: 50%;
top: 10px;
bottom: 10px;
padding: 1%;
margin: auto;
height: 880px;
background: radial-gradient(#888, #999, #aaa, #bbb, #ccc, #ddd, #eee);
}
label[for=description] {
display: block;
}
body {
background: steelblue;
}
</style>
</head>
<body>
<form>
<label for="name">Name:</label>
<input id="name" name="name"/>
<hr/>
<label for="description">Description:</label>
<textarea id="des" name="cost"></textarea>
<hr/>
<button onclick="sendData()">Create Class</button>
</form>
<script>
var n;
var descript;
function sendData() {
n = document.getElementById("name").value;
descript = document.getElementById("des").value;
var http = new XMLHttpRequest();
http.onreadystatechange = function() {
if (http.readyState == 4 && http.status == 200) {
response(http.responseText);
}
};
http.open("GET", "class_add.php?name=" + name + "&descript=" + descript, true);
http.send();
}
/*This is supposed to make the display msg*/ function response(txt) {
var p = document.createElement("p");
p.innerHTML = txt;
p.style.fontSize = "30px";
p.style.fontFamily = "Comic Sans MS";
p.style.color = "magenta";
document.body.appendChild(p);
}
</script>
</body>
</html>
您正在提交表单,页面正在重新加载并清除任何更改。按钮元素的默认类型是提交,因此请将其更改为按钮,以便单击它不会提交表单:
<button type="button" onclick="sendData()">Create Class</button>
相关文章:
- 如果localstorage为空,则显示欢迎消息
- 消息显示之外的淘汰验证
- ng消息仅在触摸时显示错误,并在错误的初始显示上转换
- 显示服务工作者状态的消息
- 如果用户输入的长度小于最小长度,则显示错误消息
- 当我的条件为true时,显示一条弹出消息
- 为我的rails应用程序显示javascript弹出消息
- javascript文本验证不起作用.警报消息没有't显示
- 如何在asp.net按钮上显示Bootstrap Autocloseable警报消息
- Parsleyjs:如何取消默认消息显示
- 有角度的ng消息显示ng重复表单上的错误
- 为什么我的 JS 代码没有将消息显示到 HTML 页面
- 如何停止 PHP 脚本的响应消息显示为页面的唯一内容
- 错误消息显示在所有分区中
- 警报消息显示我的逻辑是正确的,但谷歌Chrome's的html输出查看器显示不同的内容
- 插件Jquery Validation的错误消息显示不正确
- 鼠标悬停消息显示在图像的某些部分
- 检查文件是否存在,根据消息显示jQuery
- Jquery错误消息显示在每个字段上
- 当错误消息显示用户名和密码不匹配时,如何通过Cognito验证用户池中的用户?