Skip to content
Advertisement

Use AJAX to prevent refresh when adding to a database

I’m a computer science student, in my sophomore year. For independent learning I decided to create a website in technologies like: SQL, PHP, JS, AJAX, BOOTSTRAP. I’m trying to add content to the database, I use AJAX – I do not want to refresh the page, so I use AJAX. I manage to add the content to a database – but the page refreshes. I tried to use jquery – when I add content – to prevent refresh. The code works – but there is still a refresh.

The code that accesses the database:

JavaScript

Using ajax – to prevent refresh:

JavaScript

Advertisement

Answer

After submitting the form you have to use event.preventDefault()

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement