JavaScript
  Home arrow JavaScript arrow Page 2 - Completing a Network Processor with AJAX
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Completing a Network Processor with AJAX
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2007-01-03

    Table of Contents:
  • Completing a Network Processor with AJAX
  • Refreshing a previous topic: listing the application's full client-side code
  • Performing real networking tasks on the server: defining the QueryProcessor PHP class
  • Completing the definition for the QueryProcessor class: coding some additional methods
  • Completing the networking application: listing the full source code

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Completing a Network Processor with AJAX - Refreshing a previous topic: listing the application's full client-side code


    (Page 2 of 5 )

    As a first step to coding the PHP class that actually does all the networking stuff, first I'd like to list the complete client-side code that corresponds to this AJAX-based application as it was initially defined in the two previous articles of the series.

    Doing so, you'll have a much better idea of how the PHP class that I'm going to create later on fits with the client module. Therefore, here is the full code listing that I referenced before:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
     
    <head>
     
    <meta http-equiv="Content-Type" content="text/html; charset=iso-
    8859-1" />
     
    <title>AJAX-based Networking Processor</title>
     
    <style type="text/css">
        
    body{
          padding: 0;
          margin: 0;
          background: #fff;
       
    }
       
    h1{
          font: bold 24px Arial, Helvetica, sans-serif;
          color: #000;
          text-align: center;
          margin: 10px;
       
    }
       
    #maincontainer{ 
          width: 500px;
          height: 400px;
          background: #eee;
          padding: 5px;
          margin-left: auto;
          margin-right: auto;
          border: 1px solid #000;
       
    }
       
    #paramcontainer{
          padding: 5px;
          margin-bottom: 5px;
          background: #f5ebb1;
          font: bold 12px Arial, Helvetica, sans-serif;
          color: #000;
          border: 1px solid #999;
       
    }
       
    #leftpanel{
          float: left;
          width: 100px;
          height: 350px;
          padding: 5px;
          background: #f5ebb1;
          font: bold 12px Arial, Helvetica, sans-serif;
          color: #000;
          border: 1px solid #999;
       
    }
       
    #centerpanel{
          float: left;
          width: 254px;
          height: 350px;
          padding: 5px;
          margin-left: 5px;
          background: #ccc;
          overflow: auto;
          font: bold 12px Arial, Helvetica, sans-serif;
          color: #000;
          border: 1px solid #999;
       
    }
        
    #rightpanel{
          float: right;
          width: 100px;
     
         height: 350px;
          padding: 5px;
          background: #f5ebb1;
          font: bold 12px Arial, Helvetica, sans-serif;
          color: #000;
          border: 1px solid #999;
       
    }
       
    .databox{
          width: 348px;
          font: normal 12px Arial, Helvetica, sans-serif;
          color: #000;
        }
       
    .controlbutton{
           width: 100px;
           margin: 3px 0 3px 0;
           font: normal 12px Arial, Helvetica, sans-serif;
           color: #000;
           text-align: center;
        }
      
    </style>
     
    <script language="javascript">
       
    // send http requests
       
    function sendHttpRequest(url,callbackFunc,respXml){
          
    var xmlobj=null;
           try{
             xmlobj=new XMLHttpRequest();
           }
           catch(e){
             try{
               xmlobj=new ActiveXObject("Microsoft.XMLHTTP");
             }
             catch(e){
               alert('AJAX is not supported by your browser!');
               return false;
            
    }
          
    }
           xmlobj.onreadystatechange=function(){
             if(xmlobj.readyState==4){
               if (xmlobj.status==200){
               
     respXml?eval
    (callbackFunc+'(xmlobj.responseXML)'):eval
    (callbackFunc+'(xmlobj.responseText)');
              
    }
             
    }
           
    }
           
    // open socket connection
           xmlobj.open('GET',url,true);
           // send http header
           xmlobj.setRequestHeader('Content-Type','text/html;
    charset=UTF-8');
           // send http request
           xmlobj.send(null);
        
    }
       
    // display command results
       
    function displayCommandResults(results){
           var centpanel=document.getElementById('centerpanel');
           if(!centpanel){return};
           centpanel.innerHTML='';
           centpanel.innerHTML=results;
       
    }
       
    // initialize control panel
       
    function initializeControlPanel(){
           var form=document.getElementsByTagName('form')[0];
           if(!form){return};
           // assign 'onclick' event handlers to control buttons
           if(!form.elements[1]){return};
           form.elements[1].onclick=function(){
             sendHttpRequest('query_processor.php?data='
    +document.getElementsByTagName('form')[0].elements[0].value
    +'&command=host','displayCommandResults')};
           if(!form.elements[2]){return};
           form.elements[2].onclick=function(){
             sendHttpRequest('query_processor.php?data='
    +document.getElementsByTagName('form')[0].elements[0].value
    +'&command=ip','displayCommandResults')};
           if(!form.elements[3]){return};
           form.elements[3].onclick=function(){
             sendHttpRequest('query_processor.php?data='
    +document.getElementsByTagName('form')[0].elements[0].value
    +'&command=iplist','displayCommandResults')};
           if(!form.elements[4]){return};
           form.elements[4].onclick=function(){
             sendHttpRequest('query_processor.php?data='
    +document.getElementsByTagName('form')[0].elements[0].value
    +'&command=ping','displayCommandResults')};
           if(!form.elements[5]){return};
           form.elements[5].onclick=function(){
             sendHttpRequest('query_processor.php?data='
    +document.getElementsByTagName('form')[0].elements[0].value
    +'&command=ipconfig','displayCommandResults')};
           if(!form.elements[6]){return};
           form.elements[6].onclick=function(){
    sendHttpRequest('query_processor.php?data='
    +document.getElementsByTagName('form')[0].elements[0].value
    +'&command=netstat','displayCommandResults')};
           if(!form.elements[7]){return};
           form.elements[7].onclick=function(){
    sendHttpRequest('query_processor.php?data='
    +document.getElementsByTagName('form')[0].elements[0].value
    +'&command=mxrecords','displayCommandResults')};
           if(!form.elements[8]){return};
           form.elements[8].onclick=function(){
    sendHttpRequest('query_processor.php?data='
    +document.getElementsByTagName('form')[0].elements[0].value
    +'&command=serviceports','displayCommandResults')};
           if(!form.elements[9]){return};
           form.elements[9].onclick=function(){
             sendHttpRequest('query_processor.php?data='
    +document.getElementsByTagName('form')[0].elements[0].value
    +'&command=servicenames','displayCommandResults')};
           if(!form.elements[10]){return};
           form.elements[10].onclick=function(){
             sendHttpRequest('query_processor.php?data='
    +document.getElementsByTagName('form')[0].elements[0].value
    +'&command=scanport','displayCommandResults')};
           if(!form.elements[11]){return};
           form.elements[11].onclick=function(){
             sendHttpRequest('query_processor.php?data='
    +document.getElementsByTagName('form')[0].elements[0].value
    +'&command=nsrecords','displayCommandResults')};
           if(!form.elements[12]){return};
           form.elements[12].onclick=function(){
             var centpanel=document.getElementById('centerpanel');
             if(!centpanel){return};
             centpanel.innerHTML='';
           }
       
    }
       
    // execute 'initializeControlPanel()'
        // function when web page is loaded
       
    window.onload=function(){
           if(document.getElementById && document.getElementsByTagName && document.createElement){
             initializeControlPanel();  
           }
       
    }
      
    </script>
    </head>
    <body>
     
    <h1>AJAX-BASED NETWORKING PROCESSOR</h1>
       
    <div id="maincontainer">
         
    <form>
           
    <div id="paramcontainer">
             
    Host Name/ IP Address <input type="text" name="data"
    class="databox"></input>
           
    </div>
           
    <div id="leftpanel">
             
    <input type="button" name="host" value="Host to IP"
    class="controlbutton" title="Covert Hostname to IP
    address"></input>
             
    <input type="button" name="ip" value="IP to Host"
    class="controlbutton" title="Convert IP address to
    Hostname"></input>
             
    <input type="button" name="iplist" value="IP List"
    class="controlbutton" title="Retrieve IP list"></input>
             
    <input type="button" name="ping" value="Ping"
    class="controlbutton" title="Execute ping command"></input>
             
    <input type="button" name="ipconfig" value="IP Config"
    class="controlbutton" title="Execute ipconfig command"></input>
             
    <input type="button" name="netstat" value="Netstat"
    class="controlbutton" title="Execute netstat command"></input>
           
    </div>
           
    <div id="centerpanel"></div>
           
    <div id="rightpanel">
             
    <input type="button" name="mxrec" value="MX Records"
    class="controlbutton" title="Retrieve MX records"></input>
             
    <input type="button" name="servports" value="Service Ports" class="controlbutton" title="Retrieve service ports"></input>
             
    <input type="button" name="servnames" value="Service Names" class="controlbutton" title="Retrieve service names"></input>
             
    <input type="button" name="scanport" value="Scan Port 80" class="controlbutton" title="Scan port 80"></input>
             
    <input type="button" name="whois" value="NS Records"
    class="controlbutton" title="Retrieve NS records"></input>
             
    <input type="button" name="reset" value="Clear Panel"
    class="controlbutton" title="Clear display panel"></input>
            
    </div>
          
    </form>
        
    </div>
      
    </body>
    </html> 

    All right, now I'm assuming that the above file is already familiar to you, thus I won't review the that you learned in prior articles of the series. Instead, I recommend that you visit the following section and see how the PHP class that interacts with the previous file will be created by a few comprehensive steps.

    More JavaScript Articles
    More By Alejandro Gervasio


       · In this final article of the series, the AJAX-based networking processor is...
     

    JAVASCRIPT ARTICLES

    - More on JavaScript Array Objects
    - Methods of the DOM Location Object
    - The DOM Location Object Properties
    - Handling Remote Files with JavaScript Click ...
    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...


     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT