Server programming in Ajax Learning

Source: Internet
Author: User
First, declare: Code After reading Microsoft's video tutorial, I wrote it according to the video handout and used it on the company's internal training website. Article Content

Ajax Server programming

Server code
  • first define a class: employee public class employee <br/> {<br/> public employee (string fristname, string lastname) <br/>{< br/> This. mfirstname = firstname; <br/> This. mlastname = lastname; <br/>}< br/> private string mfirstname; <br/> Public String firstname <br/> {<br/> Get <br/> {<br/> return this. mfirstname; <br/>}< br/> private string mlastname; <br/> Public String lastname <br/> {<br/> Get <br/> {<br/> return this. mlastname; <br/>}< br/>
  • then define a getemployee. ashx, the Code is as follows: public class getemployee: ihttphandler <br/>{< br/> Public void processrequest (httpcontext context) <br/>{< br/> context. response. contenttype = "text/plain"; <br/> string firstname = context. request. params ("firstname"); <br/> string lastname = context. request. params ("lastname"); <br/> employee ID = new employee (firstname, lastname ); <br/> // serialized as a JSON object <br/> javascriptserializer serializer = new javascriptserializer (); <br/> string jsonemployee = serializer. serialize (employee); <br/> context. response. write (jsonemployee); <br/>}< br/>
  • client Program

    <br/> <input type =" button "value =" button "onclick =" showemployee ('any ', 'changshanghai'); "/> <br/>

    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.