Кстати, мне удалось установить TinyMCE, так что все выглядит красиво.
Сначала я обработал отправку исключительно с помощью php (вызвав обновление страницы):
Код: Выделить всё
if (isset($_POST["submit_hak"])) {
$con = mysqli_connect("localhost","","","");
if (mysqli_connect_errno($con)) {echo "Error: " . mysqli_connect_error();}
if (isset($_POST["name_hak"])) { $name = htmlspecialchars($_POST["name_hak"], ENT_QUOTES); }
if (isset($_POST["content_hak"])) { $content = htmlspecialchars($_POST["content_hak"], ENT_QUOTES); }
if (isset($_POST["tags_hak"])) { $tags = htmlspecialchars($_POST["tags_hak"], ENT_QUOTES); }
if (isset($_POST["id_hak"])) { $id = htmlspecialchars($_POST["id_hak"], ENT_QUOTES); }
if (isset($_POST["unique_hak"])) { $unique = htmlspecialchars($_POST["unique_hak"], ENT_QUOTES); }
$sql = "UPDATE `-notes` SET name='$name', content='$content', tags='$tags' WHERE unique_hak='$unique'";
if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); }
mysqli_close($con);
}
Я закомментировал приведенный выше код, поместил почти аналогичный код в отдельный ajax.php (см. ниже) и добавил следующий jquery. (Я вызываю jquery-4.0.0.min.js вверху страницы, кстати)
Код: Выделить всё
$(document).ready(function(){
var id = "why";
var name = "is";
var content = "this";
var tags = "not";
var unique = "working (promptly)";
$(function() {
$('.save').click(function() {
$('.status').text('going');
id = $('#id_hak').val();
name = $('#name_hak').val();
content = tinymce.get("content_hak").getContent();
tags = $('#tags_hak').val();
unique = $('#unique_hak').val();
$.ajax({
type: 'GET',
url: 'ajax.php',
data: {'id': id, 'name': name, 'content': content, 'tags': tags, 'unique': unique},
success: function(result) {
if (result == "true") {
$('.status').text('done');
setTimeout(() => {$('.status').text('');}, 1000);
} else {
$('.status').text('failed');
setTimeout(() => {$('.status').text('');}, 1000);
}
}
});
return false;
});
});
});
Код: Выделить всё
Подробнее здесь: [url]https://stackoverflow.com/questions/79875773/javascript-jquery-ajax-call-to-php-very-slow-to-even-not-working-at-all[/url]
Мобильная версия