Для формы
submit Event.preventDefault();
После отправляем AJAX запрос:
// this is the id of the form
$("#idForm").submit(function(e) {
var form = $(this);
var url = form.attr('action');
$.ajax({
type: "POST",
url: url,
data: form.serialize(), // serializes the form's elements.
success: function(data)
{
alert(data); // show response from the django.
}
});
e.preventDefault(); // avoid to execute the actual submit of the form.
});
Plain JS: XMLHttpRequestvar http = new XMLHttpRequest();
http.open('POST', url, true);
http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200) {
console.log(http.responseText);
}
}
http.send(params);
JQ Ajax$.ajax({
type: "POST",
url: url,
data: data,
success: success,
dataType: dataType
});