1

I have an undordered list

  • Aditya
  • Sam
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?

7
  • when you return a response with the name, are you still adding it to the database first? Commented Jan 15, 2011 at 19:25
  • lets see the php that handles the database entry and response. Commented Jan 15, 2011 at 19:26
  • @dqhendricks . Yes I am adding it to the database first. Commented Jan 15, 2011 at 19:35
  • but in method two, when you refresh, the item shows up? this is bizzar. please edit your code and show us the php that updates the database and returns the response to ajax. Commented Jan 15, 2011 at 19:37
  • @dqhendricks. This is what confuses me .I have two functions one which pulls all the names from the database and is used to display names on the page. Another which updates the database.Now once I update the database , the first fuction should pull up the record and dsiplay on the page. Do i still need to send a response ? Commented Jan 15, 2011 at 20:04

1 Answer 1

2

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.