JavaScript
  Home arrow JavaScript arrow Page 3 - Running Queries in the Background with a M...
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 
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

Running Queries in the Background with a MySQL Client with AJAX
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2006-09-05

    Table of Contents:
  • Running Queries in the Background with a MySQL Client with AJAX
  • Creating the application's main panel
  • Working with HTTP requester objects
  • Initializing the user panel and displaying result sets
  • Putting all the pieces together

  • 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


    Running Queries in the Background with a MySQL Client with AJAX - Working with HTTP requester objects


    (Page 3 of 5 )

     

    If you found creating the previous user panel a no-brainer process, then defining the set of JavaScript functions tasked with sending queries typed by the user and displaying the results is a slightly more complex procedure. However, if developing AJAX-based applications is quite familiar to you, the experience shouldn’t present major problems.

    First, let me show you the handy “sendHttpRequest()” function, which is responsible for sending all the entered queries to the server. Its signature is as follows:

    // 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);
    }

      

    As you can see, the above “sendHttpRequest()” function first creates, in a cross-browser fashion, an HTTP requester object, which is used later to send the query typed by the user. Also, after the corresponding request has been successfully processed, a callback function is called, either for handling a text-based response, that is by using the “responseText” property, or an XML-based result, in this case by utilizing the “responseXML” member.

    Right, at this level you know how the application will send the queries entered by the user to the server, once the “Execute” button is clicked on. Therefore, the next step consists of defining the pertinent callback function that processes all the responses received from the server, as well as another one, tasked with initializing the main user panel that you saw in the previous section.

    To see how all these tasks will be carried out, keep reading.

    More JavaScript Articles
    More By Alejandro Gervasio


       · In this second article of the series, the front end of the MySQL client application...
       · HI, I'm obviously a newbie here, the tutorial looks great, but could some one please...
       · Hello there,Thank you for the kind words on my AJAX article. Concerning your...
     

    JAVASCRIPT ARTICLES

    - Using jQuery to Preload Images with CSS and ...
    - Using Client-Side Scripting to Preload Image...
    - Removing Non-Semantic Markup when Preloading...
    - Using the Display CSS Property to Preload Im...
    - Preloading Images with CSS and JavaScript
    - Scaling and Moving Web Page Elements with th...
    - Fading, Hiding and Sliding HTML Elements wit...
    - Toggling CSS Properties with the GX JavaScri...
    - Cancel, Queue and Pause Animations with the ...
    - Producing Elastic Effects with the GX JavaSc...
    - Moving Divs Diagonally with the GX JavaScrip...
    - Moving Elements Vertically and Horizontally ...
    - Making Bouncing Effects in Parallel with the...
    - Creating Bouncing Effects with the GX JavaSc...
    - Manipulating Background Colors with the GX J...







    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 10 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek