Use XMLHTTP to get data without refreshing.

Source: Internet
Author: User
Tags object sql net return string client
xml| Data | refresh | no refresh
  • There are several ways to interact between client and server-side data.
    1. Submit, via <form></form> submit to server side. It is also called "Refresh".
    2. Submit to server by XMLHTTP without refreshing, and return data. Also known as "no Refresh" bar.
    Using XMLHTTP we can achieve a lot of very powerful applications. This article mainly introduces one of its
    A few simple applications.

    Attached: Because XMLHTTP is an object supported by ie5.0+. So you have to have ie5.0+ to see the effect.


    <script "JavaScript"
    function language= (str)
     *---------------getresult (str)-----------------
     * GetResult (str)
     * function: Sends a request through XMLHTTP to return the result.
     * parameter: str, string, send condition.
     * instance: GetResult (Document.all.userid.value);
     * author:wanghr100 (Gray bean Baby. net)
     * update:2004-5-27 19:02
     *---------------getresult (str)- ----------------
        var obao = new ActiveXObject ("Microsoft.XMLHTTP");
       //special characters: +,%,&,=, etc. transmission solutions. The string is encoded first with escape.
       //update:2004-6-1 12:22 ("POST", "server.asp?userid=" +escape (str), false);
    Obao.send ();
    Server-side processing returns a string that is encoded by escape.
    Document.all.username.value=unescape (Obao.responsetext)
    <input type= "button" value= "Get" ><br>
    Userid:<input type= "text" name= "userid" ><br>
    Username:<input type= "text" name= "username" >

    Server.asp server-side processing.

    <% @Language = "JavaScript"%>
    function Opendb (sdbname)
    *---------------opendb (sdbname)-----------------
    * OPENDB (Sdbname)
    * Function: Open database Sdbname, return conn object.
    * Parameters: Sdbname, String, database name.
    * Example: var conn = opendb ("Database.mdb");
    * AUTHOR:WANGHR100 (Grey bean baby. NET)
    * Update:2004-5-12 8:18
    *---------------opendb (sdbname)-----------------
    var connstr = "Provider=Microsoft.Jet.OLEDB.4.0;" Data source= "+server.mappath (sdbname);
    var conn = Server.CreateObject ("ADODB.") Connection ");
    Conn. Open (CONNSTR);
    Return conn;
    var sresult = "";
    var oconn = opendb ("Data.mdb");
    Special characters: +,%,&,=, etc. transmission solutions. The client character is encoded by escape
    So the server side first to pass through unescape decoding.
    Update:2004-6-1 12:22
    var UserID = unescape (Request ("userid"));
    var sql = "Select username from users where userid= '" +userid+ "";
    var rs = oconn.execute (SQL);
    if (!rs. EOF)
    Sresult = RS ("username"). Value;
    //Add fault tolerance. 2004-5-30 10:15
    Sresult = "Sorry, not found ..."
    //escape solved the XMLHTTP. Chinese to deal with the problem.
    Response.Write (Escape (Sresult));

    Database Design Data.mdb
    Table users.
    ID Auto Number
    UserID text
    Username text

    table: Users data:
    ID userid Username
    1 wanghr100 baby grey peas. Net

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.