Asynchronous first Experience

Source: Internet
Author: User

I learned a new knowledge yesterday Ajax Ajax is "asynchronous Javascript and XML "(Asynchronous JavaScript and XML) is a Web development technique that creates an interactive Web application. This is the advantage of Baidu to: through the background and the server for a small amount of data exchange, AJAX can make the Web page implementation of asynchronous update. This means that you can update a part of a webpage without reloading the entire page. Traditional Web pages (without AJAX) if you need to update your content, you must reload the entire page surface.

I have heard of this thing long ago, it sounds very big on the AH!

I think that is, register an event for a button, use a new thread to access the background when clicked, and then proceed to the following logic based on the resulting return.

In fact, Ajax is a piece of JavaScript code.

1<script src= ". /js/jquery-1.8.2.js "></script>2<script type= "Text/javascript" >3$(function () {4$ ("#btnLogin"). Click (function() {5$.get ("Plogin.ashx", {6UserName: $ ("#txtClientID"). Val (),7PWD: $ ("#txtPassword"). Val (),8Code: $ ("#txtCode"). Val ()9},function(data) {Ten                     if(data== "OK") { OneWindow.location.href = "Main.aspx"; A}Else { - alert (data); -                     } the                 }); -             }); -});

The first is the introduction of jquery, in fact, directly with JavaScript can be achieved, but jquery package for us, it is very cool to use

Register a Click event for the button, using $.get () or $.post () in the method

There is no difference between the two methods used in jquery, there are three parameters.

First: The address that needs to be requested

Second: A JSON-formatted key-value pair, which is a parameter passed to the background

The third: Pass a method in, the method has a parameter, is used to receive the data returned in the background, the method body is based on the returned data to implement the next logic.

The following is a section of my general handler code:

1  Public classlogin1:ihttphandler,irequiressessionstate2     {3 4          Public voidProcessRequest (HttpContext context)5         {6Context. Response.ContentType ="Text/plain";7             stringUserName = context. request["UserName"];8             stringPassword = context. request["PWD"];9             stringValidatecode = context. request["Code"];Ten  One             //Verification Code Check A             stringServercode = context. session["Validatecode"] ==NULL -?string. Empty -: Context. session["Validatecode"]. ToString (); the             if(Servercode = =string. Empty | | Validatecode! =Servercode) -             { -                 //Checksum Failure -Context. Response.Write ("Verification Code check failed"); +             } -             Else +             { ABll. Hksj_users BLL =Newhksj_users (); atList<model.hksj_users> list= BLL. Getmodellist (string. Format ("loginname= ' {0} ' and password= ' {1} '", UserName, Password)); -                 if(list. count>=1) -                 { -Context. session["Loginuser"] = list[0]; -Context. Response.Write ("OK"); -                 } in                 Else -                 { toContext. Response.Write ("Login Failed"); +                 } -             } the  *  $         }Panax Notoginseng  -          Public BOOLisreusable the         { +             Get A             { the                 return false; +             } -}

It is important to note that because the session is used in a generic handler, the interface implemented in this class needs to be irequiressessionstate this interface

Asynchronous first Experience

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: info-contact@alibabacloud.com 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.