Learning ASP. NET Ajax (4) asynchronous communication layer together

Source: Internet
Author: User

This blog shows the data exchange process in ASP. NET Ajax.

Employee class:

/// <Summary> /// employee class /// </Summary> public class employee {private string _ firstname; private string _ lastname; private string _ title; public Employee () {}/// <summary> /// constructor with parameters /// </Summary> /// <Param name = "firstname"> last name </param> // /<Param name = "lastname"> name </param> // <Param name = "title"> position </param> public employee (string firstname, string lastname, String title) {This. _ firstname = firstname; this. _ lastname = lastname; this. _ Title = title ;}/// <summary> /// surname /// </Summary> Public String firstname {get {return this. _ firstname ;}/// <summary> /// name // </Summary> Public String lastname {get {return this. _ lastname ;}/// <summary> // position /// </Summary> Public String title {get {return this. _ title ;}}}

Client code

Getemployee. ashx

<% @ Webhandler Language = "C #" class = "aspnetajaxoverview. getemployee "%> using system; using system. web; using system. web. script. serialization; namespace aspnetajaxoverview {public class getemployee: ihttphandler {public void processrequest (httpcontext context) {context. response. contenttype = "text/plain"; // obtain the last name, name, and position string firstname = context. request. params ["firstname"]; string lastname = context. request. params ["lastname"]; String title = context. request. params ["title"]; // instance employee class employee Employee = new employee (firstname, lastname, title); // serialized as a JSON string javascriptserializer serializer = new javascriptserializer (); string jsonemp = serializer. serialize (employee); // Response Request context. response. write (jsonemp);} public bool isreusable {get {return false ;}}}}

Server code

<% @ Page Language = "C #" autoeventwireup = "true" codefile = "2 asynchronous communication. aspx. cs" inherits = "_ 2 asynchronous communication" %> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml"> 

Running result


The data exchange process adopts the sequence diagram for visual display:

The javascript in the middle is equivalent to an asynchronous communication layer, which is responsible for data exchange between browser and server.

Related Article

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.