Skip to content
Advertisement

How can we fetch data from database in PHP using ajax and display in value of input type?

I am working with two forms where if user submitted first form the data is inserted using ajax to database and user is redirected to second form(Both Forms are in same file). When user which is present on second form presses back button the value on the input type text for form1 one to be fetched from db which is stored when user submitted the first form. My doubt is how can we pass value from ajax call to input type text Here is my code which i have done uptill now

JavaScript

Ajax Call for back button

JavaScript

ClientData.php

JavaScript

Advertisement

Answer

First, let’s change ClientData.php to return data in a more usable form.

JavaScript

Now our return will contain JSON data instead of plain strings. We can update your success method to update those input boxes.

JavaScript

This solution will dynamically update any input on your page as long as you return a key=>value pair for it from your server.

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