Answer the question
In order to leave comments, you need to log in
AJAX duplicates sending data to the server. How to be?
Please tell me who knows what could be the matter. There is a script that sends data to the server using AJAX. On this server, the data is processed and entered into the database, but for some reason they are duplicated (that is, they are entered into the database twice). Without AJAX (with page reload) everything is fine! The script is the following:
$(document).ready(function() {
$('#form').submit(function (e) {
e.preventDefault();
$.ajax({
url: '/',
type: 'POST',
data: {text: $('#message-text').val()},
});
});
});
Answer the question
In order to leave comments, you need to log in
If none of the above help, insert
.......
e.preventDefault()
e.stopImmediatePropagation()
........
or you can insert it right away =) Look at the network tab.
If the request left alone - the problem is in the backend, we are looking for it there.
If there are several requests, we write debugger;
and look for an asshole.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question