开发者

What technology use to make a webpage to update in real time?

I want to make a webpage where an user can add the title from a book he has read. These changes are reflected in real time on a list that contains all books he has introduced on the databas开发者_高级运维e, without the need to press any "reload" button. By example: there is no need to refresh (F5) the page to see the last book added.

I don't know if I can do this in PHP or in any other language, so I would like to know which is the best suited for something like this.

Thank you.


I think you are looking for Ajax. Would be able to asynchronously update the section of the page (the post in this case) without the need for page refresh.


You will want to do this with javascript, using the onchange event, and for a discussion on this you can look at: Call Javascript onchange event by programatically changing textbox value.

Basically, you react to the data being changed, then just send it immediately over using ajax to the server, but, you need to be aware of two things.

First, how will you handle errors, such as there is no book with that title, or the length is too long. I tend to put the error message in or by the place where they had the bad data.

The other is that you need to pass back the id when the data was inserted, so that when they change it again you can just do an update, so you will need to store that. I tend to put the database id I need in the element id, but you can keep it in an array in javascript, since it will maintain state for you.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜