<form method = "POST" id = "search"> {% csrf_token %}
<input name = "sdf" value = "" onkeyup="search(this.value);" onkeypress="search(this.value);" type = "search" style = "width: 100%; height: 35px; background: url(/static/simg/search-icon.png) no-repeat scroll 7px 7px; background-size: 20px 20px; padding-left:30px; color: white; font-size: 18px;" placeholder="Поиск пользавателей">
<input id = "gosearch" type = "submit" style = "">
</form>
<p id = "text">{{sn}}</p>
$("#search").submit(function (e) {
e.preventDefault()
var form_data = $(this).serialize();
$.ajax({
type: "POST",
url: "",
data: form_data,
success: function () {
$.ajax({
url: document.URL,
cache: false,
success: function(html){
}
});
}
});
});
if "sdf" in request.POST:
sn = request.POST['sdf']
$("#search").submit(function (e) {
e.preventDefault()
var form_data = $(this).serialize();
$.ajax({
type: "POST",
url: "",
data: form_data,
success: function () {
$.ajax({
url: document.URL,
cache: false,
//внесите изменения
success: dataFromServer(html){
}
});
}
});
});
//добавьте простую функцию
function dataFromServer(html):
let html = JSON.parse(html)
document.querySelector('#text').innerHTML = html