Close Search Box
Search Box

Search: From:

Close
Newsletter

9Tutorials to your Inbox



Display content dynamically with AJAX

Display content dynamically with AJAX
Author lv1 (3100/5000)
2,267 views
1 Star2 Star3Star4 Star5 Star (3 votes, average: 4.33 out of 5)

We want to design a commenting system where visitors of your website can leave a comment on a news post. The form for submitting a comment should only be visible when a “post comment button” is clicked. The comment form should be displayed without reloading the web page.

The solution

To get this behaviour we are going to use AJAX (Asyncronous Javascript And XML) which is perfect for these kind of problems. With AJAX it is possible to send requests via Javascript that updates the webpage wiithout the need of a page refresh.

We start with the html code that we later will integrate with a Javascript to reveal the hidden textbox. Create a new file and call it comments.html.

Important things to note with this code is

javascript:showForm(’comment’);

that calls the javascript function ShowForm when the link is clicked on. Also note the code

<div id=”comment” style=’display:none’>

that creates a div with the id “comment” and hides this div by default.

With the html code out of the way we can move on to the javascript part that is supposed to reveal the hidden div when the “post comment” link is clicked. To do this we add the following code to our html file.

That ’s all. Simple, right ?

del.icio.us:Display content dynamically with AJAX digg:Display content dynamically with AJAX spurl:Display content dynamically with AJAX newsvine:Display content dynamically with AJAX blinklist:Display content dynamically with AJAX furl:Display content dynamically with AJAX reddit:Display content dynamically with AJAX blogmarks:Display content dynamically with AJAX Y!:Display content dynamically with AJAX magnolia:Display content dynamically with AJAX segnalo:Display content dynamically with AJAX

Post a Comment »








Safari hates me

Comment Guidelines

  • Hyperlinks are automatically generated.
  • <em>italic</em>
  • <strong>bold</strong>
  1. EdgeVerse December 13, 2007

    Nice tutorial. But, where does the comments go. I mean.. when you type and send comment, where is it saved to? They aren’t showing up on page.

  2. Java Journals and Magazines, JSP, Javascript, AjAX, XML as Java friends « DGS about JAVA July 20, 2008

    [...] the decimal value of any character; then we’ll break apart the JavaScript and examine it , Display content dynamically with AJAX, , How to Develop Web Applications with Ajax , Creating sortable lists with PHP and Ajax , AjAX [...]