gpt4 book ai didi

javascript - echo 正在向我在 PHP 中输​​出的内容添加新行

转载 作者:行者123 更新时间:2023-11-28 10:42:57 25 4
gpt4 key购买 nike

我正在发送回显一些要在 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将被接收为“valid[newline]”/“invalid[newline]”,“valid”/“Invalid”

最佳答案

http://php.net/manual/en/function.echo.php所述这不可能是 echo 的“问题”。 -标签后必须有一些换行符

关于javascript - echo 正在向我在 PHP 中输​​出的内容添加新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49194636/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com