Answer the question
In order to leave comments, you need to log in
How to monitor the appearance of records with id in the MongoDB database when submit is clicked?
There is a form, input from the user
. When submitting, the data goes to the database (Mongo), on the back end they are transformed and returned to a separate table.
How to monitor the appearance of records with id in the database table when submit is clicked?
Please tell me how to implement it correctly. Thank you!
Answer the question
In order to leave comments, you need to log in
1) when you click on the button, you send a post-request, the body of the request contains the data to be written
2) the backend processes the record, puts it in the database, generates an ID and returns this record in JSON format
3) parse json-, encode the response into markup, add the generated markup to the table
All of the above is within an AJAX request
Detailed example:
$( "#form" ).submit(function( event ) {
event.preventDefault(); // отменяем событие по дефолту
$.post( "/ajax/add.php", { $(this).serialize() }) // отсылаем ajax запрос на добавление записи
.done(function( data ) {
alert( "Новая запись в базе: " + data ); // Получаем из add.php ответ (id записи которую вернула база)
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question