Jump to content

Creating a custom HTTP object


Wolverine68

Recommended Posts

I need to create a customized HTTP object that will get the HTTP status code name and number then use Javascript code to display the HTTP status.

Any kind of push in the right direction (online resources, tutorials, code snippets) would be appreciated. 

 

HTML:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<head>
<title>Extract Data from an XML file</title>
<style type="text/css"> 
.showIt {
           font-size: 14pt;
           color: green;
           font-family: Arial, Tahoma, Verdana;
           border: thick solid;
           padding: 10px;

         }

b        { font-size: 16pt;
           color:#000000;
         }
          
</style>

<script type="text/javascript" language="javascript"> 
<!--The object detection code -->
var req = false;
// Is there support for native XHR object?: IE7+, Firefox, Safari, Opera
     if (window.XMLHttpRequest)
    {
     req = new XMLHttpRequest();
     //create an XMLHttpRequest object
    }

     else if (window.ActiveXObject)
     //check for Version 6
    {
     req = new ActiveXObject('MSXML2.XMLHTTP.6.0');
     //create an ActiveX XMLHTTP component
    }

     if (!req)
    {
    req = new ActiveXObject('MSXML2.XMLHTTP');
    //fallback to version 3
    }

    

function goXml()
{
    if (req)
    { 
    //Request data to be retrieved from the server

    req.onreadystatechange = function() 
        {
                if (req.readyState == 4 && req.status == 200)
            {
            var response = req.responseXML;
            readXML(response);
                 }

        }
    req.open("GET", "MusicianList.xml", true);
    req.send(null);
    }
}


function readXML(response)
{
    var myResponse = response.documentElement;
    var myMusician = myResponse.getElementsByTagName("musician");
    var place = document.getElementById("showIt"); 
    for (var i=0; i < myMusician.length; i++)
    {
     place.innerHTML += "<b>Name: </b>" + myMusician[i].getElementsByTagName("name")[0].firstChild.nodeValue + "<br>";
     place.innerHTML += "<b>Genre: </b>" +myMusician[i].getElementsByTagName("genre")[0].firstChild.nodeValue + "<br>";
     place.innerHTML += "<b>Hitsong: </b>" +myMusician[i].getElementsByTagName("hitsong")[0].firstChild.nodeValue + "<br><br>";  
    }
}


//-->
</script>
</head>

<form>
Click the button to show the list: <input type="button" name="display" id="display" value="Display the List" onClick="goXml()">
</form>

<p id="showIt" class="showIt"></p>



</body>
</html>

 

XML file:

 

 


<?xml version="1.0" encoding="utf-8" ?> 
- <musicians>
- <musician>
  <name>Bruce Springsteen</name> 
  <genre>Rock</genre> 
  <hitsong>Born in the USA</hitsong> 
  </musician>
- <musician>
  <name>B.B. King</name> 
  <genre>Blues</genre> 
  <hitsong>The Thrill Is Gone</hitsong> 
  </musician>
- <musician>
  <name>Tim McGraw</name> 
  <genre>Country</genre> 
  <hitsong>Live Like You Were Dying</hitsong> 
  </musician>
- <musician>
  <name>Gordon Lightfoot</name> 
  <genre>Folk</genre> 
  <hitsong>Carefree Highway</hitsong> 
  </musician>
- <musician>
  <name>Glenn Miller</name> 
  <genre>Big Band</genre> 
  <hitsong>In The Mood</hitsong> 
  </musician>
  </musicians>

     

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.