我有一个输入字段,正在发送到服务器,检查,然后返回。奇怪的是,当它返回时,它最终看起来像一个标签符。
jQuery的:
var name = $("#name").val();
$.ajax({
url: "JSON/checkName.php",
data: "name=" + name,
method: "POST"
})
.done(function(msg) {
alert("msg: " + msg + ". Name: " + name + ".");
}
})
checkName.php:
<?php
require_once "../dbPDO.php";
function clean($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$name = clean($_POST["name"]);
$sql = "SELECT * FROM `names` WHERE `name` = '$name' AND `valid` = TRUE";
$stmt = $DBcon->prepare($sql);
$stmt->execute();
$count = $stmt->rowCount();
if($count == 1) {
echo $name;
} else {
echo "Error";
}
?>
运行此功能后,将显示警告对话框:
msg: James . Name: James.
......应该显示:
msg: James. Name: James.
有什么想法吗?