I send the data from the html form to the server with a simple ajax request:

$.ajax({ type: "POST", url: "add_data.php", data: $('#form').serialize(), success: function(data) { $('#success').html(data); $('#form')[0].reset(); $('#success').fadeOut(4000); } }); 

The server returns the response that appears in #success. But for some reason this only happens when you first send data. With the second, third, etc. data is successfully entered into the database, but the answer from the server in #success does not appear.

If you reload the page, the answer again comes once, and then no.

Why is this happening and how to fix it?

  • and in the browser console what? - Vartlok
  • @Vartlok is empty (no error) - humster_spb
  • one
    why don't you know - on the client - console.log (...) or alert, if you want, on the server - if php - error_log (...), still var_dump (...) is very useful if on the server node .js - also console.log () :-) - Eugene Bartosh
  • one
    start at least with console.log (data); in the success function - Alexus
  • one
    add $('#success').show(); before $('#success').html(data); - Igor

1 answer 1

For each sub, reset the output field to:

 $('#success').html('').show(); 
  • one
    Well, almost like this: I just added $ ('# success'). Show () before $ ('# success'). Html (data); - humster_spb