<script type="Text/javascript"Src="Jquery-1.9.1.js"></script> <script type="Text/javascript">function Test () {$.ajax ({type:"Get", Cache:false, URL:".. /.. /ajax/task.aspx", Data:'ID =1',//URL after parametersuccess:function (JSON) {JSON= eval ("("+ JSON +")"); $.each (JSON, function (I, item) {Alert (parseint (Item.iname), parseint (item . IID)); }); }, Error:function (msg) {alert ("Error:"+msg); } }); } </script>
Background code: Public voidProcessRequest (HttpContext context)//just an example to learn{context. Response.ContentType="Application/json"; string[] Arraya =New string[] {"Zhang San","John Doe","Wang er","Zhao" }; stringreturns =""; Returns="{\ "people\": ["; for(inti =0; i < arraya.length; i++) {returns+="[{\ "iname\": \ ""+ Arraya[i] +"\ ", \" iid\ ": \" 001\ "}]"+ (I! = (Arraya.length-1) ?",":""); } returns+="]};"; Context. Response.Write (returns);//after the return is the JSON format directly defined in JS above .}