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/>