// JSON. the public void processrequest (httpcontext context) {context. response. contenttype = "text/plain"; javascriptserializer JSON = new javascriptserializer (); string JS = JSON. serialize (new person () {name = "anby", age = "20"}); context. response. write (JS);} // front-end Code <SCRIPT src = "scripts/jquery-1.7.1.min.js"> </SCRIPT> <SCRIPT type = "text/JavaScript" >$ (function () {$. post ("JSON. ashx ", function (data, state) {If (State =" success ") {var person = $. parsejson (data); alert (person. name) ;}})}); </SCRIPT>
// Ashx code public void processrequest (httpcontext context) {context. response. contenttype = "text/plain"; var STR = context. request ["money"]. tostring (); context. response. write (STR );} // front-end JavaScript code <SCRIPT src = "scripts/jquery-1.7.1.min.js"> </SCRIPT> <script language = "JavaScript" type = "text/JavaScript"> function button1_onclick () {var money = $ ("# text1 "). val (); $. post ("getself. ashx ", {" money ": Money}, function (data, state) {If (State =" success ") {alert ("this is returned by the server" + Data) ;}}</SCRIPT>