我想创建像这样的错误消息
不允许空格请再试一次
如果输入是firstname
中的空格,我是否需要为姓氏重复ajax?在表单html中使用其他操作update.php
时不会发生冲突吗?
<!DOCTYPE html>
<html>
<head>
<script>
function showError(str) {
if (str == "") {
document.getElementById("txtError").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("txtError").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","resident/residenterrormessage.php?g="+str,true);
xmlhttp.send();
}
}
</script>
</head>
<body>
<form action="update.php" meth="POST">
<div id="txtError">Error Message</div>
<input onchange="showError(this.value)" title="First Name" name="firstname" type="text">
<input title="Last Name" name="lastname" type="text" value="">
<input type="submit" name="submit">
<input>
</form>
</body>
</html>
这是我驻留在文件夹中的residenterrormessage.php
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link href="css/w3.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<?php
$firstname = str_replace(" ", "", $_GET["g"]);
if(empty($firstname) ){
echo '<h1>"SPACE Not Allowed Please Try Again"</h1>';
}
?>
</body>
</html>
答案 0 :(得分:0)
根据您的代码,您将在div中追加整页。所以我在你的代码中做了一些编辑。您可能想尝试编辑您的residenterrormessage.php到此
if (jarray.length() ==0 )