Aditya Shukla
Aditya Shukla

Reputation: 14225

Adding to database using ajax

I have an undordered list

which contains the names of people from a table. Now I am adding another name to the database using ajax .The names get inserted properly in the database, but I have to refresh the page to see the changes(which is certainly not wanted).

This part confuses me.

1)If I return a response to javascript which gives the "Name" and I add a list element "Name" to the dom.Then on page refresh, that element is not found on the page.

2)If i do not return a response and just add to database , then i have to refresh the page to see the changes.

I am using plain javascript based ajax call , not using jquery etc.

How to fix this issue?

Upvotes: 1

Views: 634

Answers (1)

Alfred
Alfred

Reputation: 61783

I am using plain javascript based ajax call , not using jquery etc.

You should learn to use xmlhttprequest if you want to do it without jquery(or any other kind of framework). You should also learn to append text/html to an element. Basically you will need to learn javascript the old fashion way, but keep in mind only to use the "good parts of javascript".

But in my opinion you should use jquery instead(have not heard compelling reason why you are not using it) because that will make javascript development a lot easier. You can achieve this easily by using:

  1. use http://api.jquery.com/jQuery.post/ to add item to the database.
  2. next add item to unordered list using jquery.

Upvotes: 2

Related Questions