开发者

Adding to database using ajax

开发者 https://www.devze.com 2023-02-04 05:01 出处:网络
I have anundordered listAdityaSam which contains the names of people from a table. Now I am adding another name to the da开发者_StackOverflow社区tabase using ajax .The names get inserted properly in t

I have an undordered list

  • Aditya
  • Sam
which contains the names of people from a table. Now I am adding another name to the da开发者_StackOverflow社区tabase 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?


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.
0

精彩评论

暂无评论...
验证码 换一张
取 消