Answer the question
In order to leave comments, you need to log in
Why is the variable not updated on the front?
<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']
Answer the question
In order to leave comments, you need to log in
for example, make changes to the js script
$("#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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question