Total members 9950 | Gratitudes |It is currently Sat Feb 11, 2012 3:03 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Question
 Question subject: My First Ajax application
PostPosted: Mon Aug 06, 2007 10:56 am 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2103
Location: Earth
Has thanked: 39 time
Have thanks: 56 time

Hi,
Here is the my first Ajax application , this application is so simple.The ajax application read an xml file from the server and load some data from it.

Here is the html file :
Code:
<html>
<script type="text/javascript">
//read data from xml file
function getXMLdata()
{
var request=null;

  //Depends on the your browser
    if(window.XMLHttpRequest)   
   {
       //Mozila FireFox
   request=new XMLHttpRequest();
   }
   else if(window.ActiveXObject)
   {
       //Internet Explore
   request = new ActiveXObject("Microsoft.XMLHTTP");
   }
   
   if(request)
   {
   //The autocalled funtion when the status changed
request.onreadystatechange = function() {

//Status cases of the readState varrible
  if(request.readyState==0)
document.getElementById('status').innerHTML='Uninitialized';
else  if(request.readyState==1)
document.getElementById('status').innerHTML='Loading...';
else  if(request.readyState==2)
document.getElementById('status').innerHTML='Loaded';
else  if(request.readyState==3)
document.getElementById('status').innerHTML='Interactive';
else  if(request.readyState==4)
{
document.getElementById('status').innerHTML='Completed';
var xml_response = request.responseXML;
xml_response.loadXML(request.responseText);
    var myname=xml_response.getElementsByTagName('name');
    document.getElementById('Txtdata').value=myname[0].childNodes[0].nodeValue;
}

}
     
   request.open("GET","Data.xml");
   //send the request
   request.send(null);
   
   }
   else
   //not request opened
   document.getElementById('Txtdata').value='Nothing';
}

</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- used for as a meta informaton to the browser -->
<title>Untitled Document</title>
</head>

<span id = "status"></span ><br>
<input type="text" id="Txtdata" />
<input type="button" value="Load"  onclick="getXMLdata();" />
<body>
</body>
</html>


And here is XML file :
Code:
<?xml version = "1.0" ?>
<Boss>
<name>AAA</name>
<age>43
</age>
<sex>Male
</sex>
<name>ALI</name>
<age>43
</age>
<sex>Male
</sex>
</Boss>


In the beging i faced an problem when i tried to show the data. Every time i had to got " undefined " instead of the real data.The problem was in the following part of the code.
document.getElementById('Txtdata').value=myname[0].childNodes[0].nodeValue;
You have to take care where is your element postion in the xml file and which node you want to get data from ..

I post this code , just to make it easy for people to find the solution if they faced the same problem as i faced it .
Any problem you can reply to my post .

Thanks alot , :grin:

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  


 Similar topics
 Topic title   Forum   Author   Comments 
 Sending One lakh character in ajax  AJAX  Anonymous  0
 Ajax Source code to Suggest application with JSP Server side  AJAX  msi_333  5
 I need chat application using php  PHP  Anonymous  0
 [Ajax/PHP] Registration - Check for empty textboxs  AJAX  PF2G  0
 creating application  Java  Anonymous  0

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team