我发送回调一些要在Javascript中接收的数据但是当我调试它时,似乎添加了一个新行。
PHP
<?php
header("Content-Type: application/json; charset=UTF-8");
require './connection.php';
$obj = json_decode($_POST["x"], false);
$usernamequery = "SELECT * FROM User WHERE username='$obj->newUser'";
$result = mysqli_query($db, $usernamequery);
$row = mysqli_fetch_assoc($result);
if($row["Username"] == null){
$updatequery = "UPDATE User SET User='$obj->newUser' WHERE username ='$obj->username'";
$result = mysqli_query($db, $updatequery);
echo "valid";
} else{
echo "invalid";
}
?>
JS
///// USERNAME
$(document).ready(function () {
$("#userSubmitForm").on("click", function(e) {
$username = document.getElementById("user").value;
$newUser = document.getElementById("newUser").value;
user = $newUser;
obj = { "username":$username, "newUser":$newUser};
dbParam = JSON.stringify(obj);
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
validity = this.responseText;
if (validity === "valid"){
$('#usernameModal .modal-header .modal-title').html("Result");
$('#usernameModal .modal-body').html("Your Username Has Been Changed to '$newUser'");
$("#passSubmitForm").remove();
$("#userCloseForm").remove();
window.setTimeout(redirect,3000);
} else{
$('#error').html("This Username Already Exists"); ;
}
}
};
正在发生的事情是responseText将收到&#34;有效&#34; /&#34;无效&#34; as&#34;有效[换行符]&#34; /&#34;无效[换行符]&#34;
答案 0 :(得分:0)
如http://php.net/manual/en/function.echo.php所述,这不是一个&#34;问题&#34;回声。在-tags
之后必须有一些换行符答案 1 :(得分:-1)
一个简单的解决方案就是修改你的响应文本:Glide.with(context)
.load(SERVER_HOST + data.get(position).getImage())
.into(holder?.imageView);
,以便将其从不需要的空格/制表符/换行符中删除。