Web Standards
  Home arrow Web Standards arrow Page 3 - Getting Connected with Firefox and Chrome
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? 
WEB STANDARDS

Getting Connected with Firefox and Chrome
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 2
    2008-06-19

    Table of Contents:
  • Getting Connected with Firefox and Chrome
  • Connecting PHP to MySQL
  • Calling the MySQLi API, continued
  • Troubleshooting

  • 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


    Getting Connected with Firefox and Chrome - Calling the MySQLi API, continued


    (Page 3 of 4 )

    Within the JavaScript code, first we need to make certain we are responding to the correct command, so we add a global variable at the top of the source file to hold the last command issued:

      var K_XUL_NAMESPACE = "http://www.mozilla.org/keymaster/
          gatekeeper/there.is.only.xul";

      var USER_LOGGED_IN = 0;

      var lastCommand = "";
     

    and modify the doLogin function to save the last command sent:

      function doLogin(event) {

      try { // try
      var theArgs = new Array;
      theArgs[0] = new commandArg("un",document.getElementById("userName").value);
      theArgs[1] = new commandArg("pd",document.getElementById("password").value);
     
    lastCommand = "login";
      doServerRequest("login",theArgs);
       } // try
       catch (e) { //
       
    alert("doLogin exception: " + e);
       }//
      }

    When processing the server response, we use the JavaScriptsplit()function to break our comma-delimited responses into an array of name-value pairs. We then compare the value of the first entry to"true"before extracting the second returned value and setting the status text:

      function retrieveServerResponse() {
       if (theServerRequest.readyState == 4) { // all done
        // Check return code
         if (theServerRequest.status == 200) { // request terminated OK
          dump("Received from server: " + theServerRequest.responseText + "\n");

          //
          var theResults = theServerRequest.responseText.split(",");
          //

          var rCode = (theResults[0].substring((theResults[0].indexOf("=")+1),
                                    theResults[0].length)).toLowerCase();

          if (lastCommand == "login") { // process login command

          if (rCode == "true") { // everything OK, we know next parameter is
                                
    // session info
           var lastSession = "Last login was ";
           lastSession += (theResults[1].substring((theResults[1].indexOf("=")+1),
                                  
    theResults[1].length)).toLowerCase();
           loginOK();
           setStatusText(lastSession);

          } // everthing OK
         
    else { // user NG
           loginFail();
           setStatusText("No user logged in");
          } // user NG

         } // process login command

        } // request terminated OK
        else { // something is wrong
         alert("Response failed.");
        } // something is wrong
       } // all done
      }

    This version of the program will now log into the database, and if the username and password match (and the account is active), the welcome screen will include a status line along the bottom of the display reporting the last date and time of the user’s login:

      Last login was 0000-00-00 00:00:00

    All zeros appear because our initial script to create the database tables did not set an initial date in the database. Once we log in under a valid account name, the next login will yield a more welcoming message. 

    More Web Standards Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Programming Firefox," published by...
     

    Buy this book now. This article is excerpted from chapter four of Programming Firefox, written by Kenneth C. Feldt (O'Reilly, 2007; ISBN: 0596102437). Check it out today at your favorite bookstore. Buy this book now.

    WEB STANDARDS ARTICLES

    - Completing a Configuration for Chrome and a ...
    - Getting Connected with Firefox and Chrome
    - Configuring Servers and Databases with Chrome
    - Configuring Firefox for Chrome and a Server
    - Designing the Elements of a Web Page
    - Matching div heights with CSS and JavaScript
    - Forms
    - Get Down With Markup
    - If I Said You Had a Beautiful Body...
    - Web Standards in Dreamweaver Part 3
    - Web Standards in Dreamweaver, Part 2
    - Web Forms
    - Making Lists Using XHTML
    - Web Standards in Dreamweaver, Part 1







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