JavaScript
  Home arrow JavaScript arrow Page 4 - 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 
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

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 - Initializing the user panel and displaying result sets


    (Page 4 of 5 )

    In order to continue defining the rest of the JavaScript functions that integrate the MySQL client, first I’ll create a new one, called “initializeCommandPanel()”. As its name suggests, all this function does is set up some useful initialization tasks, such as placing the mouse cursor inside the command box when the web page is loaded, as well as attaching the previous “sendHttpRequest()” function to the respective “Execute” button.

    Having explained all the tasks performed by the “initializeCommandPanel()” function, below you can see how it looks:

    // initialize command panel
    function initializeCommandPanel(){
        // get 'query' field
        var query=document.getElementsByTagName('form')[0].elements
    [0];
        if(!query){return};
        query.focus();
        // get 'execute' button
        var execbtn=document.getElementsByTagName('form')[0].elements
    [1];
        if(!execbtn){return};
        // send http request when 'execute' button is clicked on
        execbtn.onclick=function(){
            // send request & execute query on MySQL server
            sendHttpRequest('mysql_server.php?
    query='+query.value,'displayResult',false);
        }
    }

    Indeed, one of the most important processes that this function performs is with reference to triggering an HTTP request to the “mysql_server.php” file each time the “Execute” button is clicked. Please notice how every time this file is requested, the value of the query entered in the command box is passed to the mentioned file, in order to be processed on the server. Now, are you starting to understand how a given database can be queried by using a comprehensive application? I bet you do!

    Okay, now that you understood how the “initializeCommandPanel()” function works, let me show you the signature of the other one, in this case called “displayResult()”, which is responsible for displaying all the results returned by a specific query. Its definition is as follows:

    // display query results
    function displayResult(result){
       
    var console=document.getElementById('console');
       
    if(!console){return};
        console.innerHTML='';
        console.innerHTML=result;
    }

    If you were thinking that the signature of the above function was much longer, you were wrong! As you can see, all this function does is first receive the response from the server (in this case obtained by the popular “responseText” property that belongs to the current requester object), then clear the DIV identified as "console," and finally display the results returned by the executed query. Simple and efficient, right?

    At this stage, I have defined the complete set of JavaScript functions that make up the client-side layer of the MySQL application. Now, it’s time to put all the pieces together, that is the respective JavaScript code and the (X)HTML markup, and see how each of them fit into each other.

    To see how the full client-side code of the application looks, please read the following section.

    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

    - 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 1 hosted by Hostway
    Stay green...Green IT