Academic Tutorials



English | French | Portugese | German | Italian
Google

Home Source Codes E-Books Downloads Contact Us About Us

AJAX Tutorial
AJAX Introduction
AJAX Example
AJAX Browsers
AJAX Source
AJAX Server
AJAX Database
AJAX XML
AJAX XMLHTTPRequest

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
AJAX Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PHP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
.NET (dotnet)
Microsoft.Net
XML Web Services
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills


AJAX Database

Previous Next


  • You can use AJAX for interactive communication with a database


  • AJAX Database Example

    The folowing example will demonstrate how a web page can fetch information from a database using AJAX technology.

    AJAX Example Explained
    <html>
    <head>
    <script src="vyom.js"></script>
    </head>
    <body>
    <form>
    Select a Customer:
    <select name="customers" onchange="showCustomer(this.value)">
    <option value="ALFKI">Matrin Luther
    <option value="NORTS ">Bil Gates
    <option value="WOLZA">Newton
    </select>
    </form>
    <p>
    <div id="txtHint"><b>Customer info will be listed here.</b></div>
    </p>
    </body>
    </html>

    The output of this simple HTML form willbe a drop down box called "customers".

    The paragraph below the form contains a div tag called "txtHint". The div is used as a placeholder for info retrieved from the web server.

    When the user select data, a function called "showCustomer()" is executed. The execution of the function is triggered by the "onchange" event of the javascript . In other words: Each time the user can change the value in the drop down box, the function showCustomer is called.

    The JavaScript code is listed below

    The AJAX JavaScript
    This is the JavaScript code stored in the file "vyom.js":
    var xmlHttp

    function showCustomer(str)
    {
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
    alert ("Browser does not support HTTP Request")
    return
    }
    var url="getcustomer.asp"
    url=url+"?q="+str
    url=url+"&sid="+Math.random()
    xmlHttp.onreadystatechange=stateChanged
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    }

    function stateChanged()
    {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
    document.getElementById("txtHint").innerHTML=xmlHttp.responseText
    }
    }

    function GetXmlHttpObject()
    {
    var objXMLHttp=null
    if (window.XMLHttpRequest)
    { objXMLHttp=new XMLHttpRequest()
    }
    else if (window.ActiveXObject)
    {
    objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
    return objXMLHttp
    }




    The AJAX Server Page

    The server paged called by the JavaScript, is a simple ASP file having name "getcustomer.asp"

    The page is written in VBScript for the Internet Information Server (IIS). It could easily be rewritten in PHP, or some other server languages.

    The code runs an SQL against a database and returns the results as an HTML table:

    sql="SELECT * FROM CUSTOMERS WHERE CUSTOMERID="
    sql=sql & request.querystring("q")

    set conn=Server.CreateObject("ADODB.Connection")
    conn.Provider="Microsoft.Jet.OLEDB.4.0"
    conn.Open(Server.Mappath("/db/vyom.mdb"))
    set rs = Server.CreateObject("ADODB.recordset")
    rs.Open sql, conn

    response.write("<table>")
    do until rs.EOF
    for each x in rs.Fields
    response.write("<tr><td><b>" & x.name & "</b></td>")
    response.write("<td>" & x.value & "</td></tr>")
    next
    rs.MoveNext
    loop

    response.write("</table>")


    Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
    • blinkbits
    • BlinkList
    • blogmarks
    • co.mments
    • connotea
    • del.icio.us
    • De.lirio.us
    • digg
    • Fark
    • feedmelinks
    • Furl
    • LinkaGoGo
    • Ma.gnolia
    • NewsVine
    • Netvouz
    • RawSugar
    • Reddit
    • scuttle
    • Shadows
    • Simpy
    • Smarking
    • Spurl
    • TailRank
    • Wists
    • YahooMyWeb


    Previous Next

    Keywords: web applications, ajax javascript xml, ajax javascript framework, ajax javascript asynchronous


    HTML Quizes
    HTML Quiz
    XHTML Quiz
    CSS Quiz
    TCP/IP Quiz
    XML Quizes
    XML Quiz
    XSL Quiz
    XSLT Quiz
    DTD Quiz
    Schema Quiz
    XForms Quiz
    XSL-FO Quiz
    XML DOM Quiz
    XLink Quiz
    XQuery Quiz
    XPath Quiz
    XPointer Quiz
    RDF Quiz
    SOAP Quiz
    WSDL Quiz
    RSS Quiz
    WAP Quiz
    Web Services Quiz
    Browser Scripting Quizes
    JavaScript Quiz
    VBScript Quiz
    AJAX Quiz
    DHTML Quiz
    HTML DOM Quiz
    WMLScript Quiz
    E4X Quiz
    Server Scripting Quizes
    ASP Quiz
    PHP Quiz
    PERL Quiz
    SQL Quiz
    ADO Quiz
    .NET (dotnet) Quizes
    Microsoft.Net Quiz
    XML Web Services Quiz
    ASP.Net Quiz
    .Net Mobile Quiz
    C# : C Sharp Quiz
    ADO.NET Quiz
    VB.NET Quiz
    Multimedia Quizes
    SVG Quiz
    Flash Quiz
    Media Quiz
    SMIL Quiz
    Web Building  Quizes
    Web Browsers Quiz
    Web Hosting Quiz
    W3C Quiz
    Web Building Quiz
    Web Quality Quiz
    Web Semantic Quiz
    Web Careers Quiz
    Java Quizes
    Java Quiz
    JSP Quiz
    Servlets Quiz
    Struts Quiz
    EJB Quiz
    JMS Quiz
    JMX Quiz
    Programming Langauges Quizes
    C Quiz
    C++ Quiz
    Visual Basic Quiz
    Data Structures Using C Quiz
    Soft Skills Quizes
    Communication Skills Quiz
    Time Management Quiz
    Project Management Quiz
    Team Work Quiz
    Leadership Skills Quiz
    Corporate Communication Quiz
    Negotiation Skills Quiz

    Privacy Policy
    Copyright © 2003-2008 Vyom Technosoft Pvt. Ltd., All Rights Reserved.