Home arrow JavaScript arrow Page 5 - JavaScript Remote Scripting: Reading Data From the Server

JavaScript Remote Scripting: Reading Data From the Server

Client-server interaction achieved without involving page reloads has become very popular for Web services. This can be handled in a variety of ways. This article covers several of them, starting with Asynchronous JavaScript and XML (AJAX).

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 39
September 21, 2005
  1. · JavaScript Remote Scripting: Reading Data From the Server
  2. · A non-standard approximation: reading server data with AJAX
  3. · Checking asynchronous http requests: taking a look at the "statusChecker()" function
  4. · Displaying file contents: defining the "createDataContainer()" and "displayData()" functions
  5. · Reusing the source code: listing the full script

print this article

JavaScript Remote Scripting: Reading Data From the Server - Reusing the source code: listing the full script
(Page 5 of 5 )

As I said before, below is the full source code for the JavaScript program that you just saw. As usual, feel free to tweak the script and modify it to fit your particular needs:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script type="text/javascript">
// initialize XMLHttpRequest object
var xmlobj=null;
// initialize global variables
var data=new Array();
var i=0;

// send http request
function sendRequest(doc){
    // check for existing requests
        // instantiate object for Firefox, Nestcape, etc.
        xmlobj=new XMLHttpRequest();
            // instantiate object for Internet Explorer
            xmlobj=new ActiveXObject('Microsoft.XMLHTTP');
            // Ajax is not supported by the browser
            return false;
    // assign state handler
    // open socket connection
    // send request

// check request status
function stateChecker(){
    // if request is completed
        // if status == 200 display text file
            // create data container
            // display data into container
            alert('Failed to get response :'+ xmlobj.statusText);

// create data container
function createDataContainer(){
    var div=document.createElement('div');
        div.style.border='1px solid #00f';
        div.style.font='bold 11px Tahoma,Arial';

// display data at a given time interval
function displayData(){

// execute program when page is loaded
    // check if browser is DOM compatible
    if(document.getElementById &&
       document.getElementsByTagName &&
        // load data file

To wrap up

That's all for now. In the second part of this article, I'll explain how to use JavaScript remote scripting for working directly with XML files by using AJAX technology. Also, I'll run through an illustrative example, helpful to implement within many client-side programs. Considering that remote scripting can boost considerably modern Web applications, the topic is worthy of review. See you soon!

DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus

- Project Nashorn to Make Java, JavaScript Wor...
- JavaScript Virus Attacks Tumblr Blogs
- Google Releases Stable Dart Version, JavaScr...
- Khan Academy Unveils New JavaScript Learning...
- Accessing Nitro? There`s an App for That
- JQuery 2.0 Leaving Older IE Versions Behind
- Fastest JavaScript Engine Might Surprise You
- Microsoft Adjusting Chakra for IE 10
- Brendan Eich: We Don`t Need Google Native Cl...
- An Overview of JavaScript Statements
- An Overview of JavaScript Operators
- Overview of JavaScript Variables
- More of the Top jQuery Social Plugins
- The Top jQuery Social Plugins
- More of the Top jQuery Slider Plugins

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials