Answer the question
In order to leave comments, you need to log in
Why is extra text (html markup) displayed in the alert?
After the ajax success request, the function should output "Working" (Which is returned by the php request handler). The very top line does indeed display what you need, but other than that, the html markup of one of my documents.
Here is the ajax send code:
function change_description() {
const penbtn = $('.mypage__change-descr');
penbtn.click(function () {
const changeForm = penbtn.parent().siblings('.mypage__write-descr').eq(0);
const closeBtn = changeForm.find('.mypage__write-descr-header-close');
const submit = closeBtn.siblings('.mypage__write-descr-header-submit');
changeForm.slideToggle('fast');
closeBtn.click(function () {
changeForm.slideUp('fast');
});
submit.click(function () {
const descrText = changeForm.children().eq(1).val();
$.ajax({
type: 'POST',
// url: 'php-scripts/my-pageHandler.php',
dataType: 'html',
data: {
descrText: descrText
},
success: function (data) {
const descriptionBox = $('.mypage__description p');
descriptionBox.text(descrText);
changeForm.slideUp('fast');
alert(data);
}
});
});
});
}
function change_description()
{
if (isset($_POST['descrText'])) {
require __DIR__ . '/../#DATABASE.php';
$newDescription = htmlspecialchars($_POST['descrText']);
$id = $_SESSION['user']['id'];
$query = $db->prepare(
"UPDATE `users` SET `description`=:description WHERE `id`='$id'"
);
$param = ['description' => $newDescription];
$query->execute($param);
echo 'Работает';
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question