5,446,823 members and growing! (16,907 online)
Email Password   helpLost your password?
Web Development » Client side scripting » General     Advanced

Refresh Portion Of Your Web Page Using XMLHTTP

By Dhandapani Ammasai

This article explains how portion of a web page can be selectively refreshed using XMLHTTP
Javascript, XMLNT4, Win2K, Windows, ASP, Dev

Posted: 15 May 2001
Updated: 15 May 2001
Views: 172,225
Bookmarked: 56 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
22 votes for this Article.
Popularity: 5.63 Rating: 4.19 out of 5
1 vote, 10.0%
1
2 votes, 20.0%
2
0 votes, 0.0%
3
2 votes, 20.0%
4
5 votes, 50.0%
5

Introduction

Did you ever have to refresh only selective part of a web page without having to refresh the whole page?. If yes, you are not alone. Fortunately, there are number of solutions which can address this issue, including remote scripting and XMLHTTP. This articles explains how a part of web page can be refreshed by using XMLHTTP, without having to refresh the whole page .

XMLHTTP

XMLHTTP object can be used to make HTTP request from the web browser to the server. XMLHTTP is part of Microsoft's XML parser and it is already installed in your machine if you have Internet Explorer.

Please refer MSDN help on how to use XMLHTTP object. Also, I recommend you reading my article Making HTTP Communication from MFC/Windows Application first, because I use the same techniques here too.

Example

Sample app screenshot

In the above example web page, we can select a country from the country list box. For a country selected, we'll display list of states/province for that country. When you click on a country, a HTTP request to the web server will be send to get all the states for the specific country. States list box will be refreshed with the result from the server. Note that we are not using the submit to send a HTTP request to the web server. Instead, we use XMLHTTP since we do not want the whole page refreshed. Also, note that both request and response are in XML string and we will have to use the XML DOM to read the node values.

If you selected Canada in the country list box, the XML request string which is send from the web browser to the web server will look like below:

<RequestStates Country='Canada'></RequestStates>

The server (i.e. states.asp in this case) will process this request and sends back XML response, which looks like as shown below:

<Response>
	<State>Alberta
	<State>British Columbia
	<State>Ontario
	<State>Quebec
</Response>

The client has to process this XML response and update the states list box. The DisplayStates() function in demo.html takes care of this functionality.

Related Articles

The article Refreshing only part of your Web Page is on the same topic. However, it uses remote scripting (not XMLHTTP) to refresh part of web page.

Installation Notes

Download the sources (states.asp and demo.html) to the root directory of your web server. Note that the sample application assumes that your web server runs on the same machine as the client. If your web server runs on different machine, you have to change the URL name in XMLHTTP's open() method (in demo.html) appropriately. This sample application will not work if the URL specified is wrong.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Dhandapani Ammasai


Dhandapani Ammasai(Dan in short) is a software delivery manager at Satyam Computer Services in Chennai,India. Dan manages large software project teams that are working on multiple projects for various well respected global Banking customers. Dan takes pride in providing vision and leadership that provide quality and higher value add solutions that satisfies all stake holders involved.

Location: United States United States

Other popular Client side scripting articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 31 (Total in Forum: 31) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralPlease use MSXML2.XMLHTTP and MSXML2.DOMDocumentmemberUmut Alev22:13 17 Dec '06  
GeneralRefreshmemberDavid Pfahl13:17 7 Dec '05  
GeneralAJAX.netmemberSean Rock0:47 2 Jul '05  
GeneralServer to client transfermembersundarbunny23:35 8 Jun '05  
GeneralRe: Server to client transfermemberHazem Salem11:41 1 Nov '06  
Generaljavascript!sussAnonymous16:55 27 Sep '04  
GeneralRe: javascript!memberAlex Korchemniy8:35 18 Dec '04  
GeneralXMLHTTP question?sussVeddy10:53 7 Oct '03  
Generalsubmit + iframes vs. xmlhttpsussNidi Iacobsohn3:27 1 Jun '03  
GeneralRe: submit + iframes vs. xmlhttpmemberrobpinion20:39 21 Jul '03  
GeneralRe: submit + iframes vs. xmlhttpsussAnonymous2:36 13 Oct '05  
Generalxmlhttpmemberarvindsha9:46 27 Nov '02  
Generalmissing value attributemember9key12:43 31 May '02  
GeneralGreat piece of code!memberJulian Tysoe5:56 30 Jan '02  
Generalforeing CharactersmemberHector11:50 2 Nov '01  
GeneralRe: foreing CharactersmemberSandro Araújo8:27 16 Nov '01  
GeneralClient requirements?memberTom Archer3:35 22 May '01  
GeneralRe: Client requirements?memberGerald7:25 22 May '01  
GeneralRe: Client requirements?memberTom Archer7:47 22 May '01  
GeneralRe: Client requirements?memberGerald8:00 22 May '01  
GeneralRe: Client requirements?memberJason Gerard9:42 23 May '01  
GeneralRe: Client requirements?memberDhandapani Ammasai9:46 23 May '01  
GeneralRe: Client requirements?memberWhiteTrailerTrash6:11 23 Nov '06  
GeneralRe: Client requirements?memberGary Menzel14:40 25 Jul '01  
GeneralRe: Client requirements?memberMark Bruk16:46 5 Sep '01  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 15 May 2001
Editor: Paul Watson
Copyright 2001 by Dhandapani Ammasai
Everything else Copyright © CodeProject, 1999-2008
Web20 | Advertise on the Code Project