JQuery的四中异步获取后台代码方法
<!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"> <head> <title></title> <script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { $("#Getjson").click(function () { $.getJSON("ProceseAjaxJson.ashx", "b=3", function (date) { alert(date[0].CityName); }); }); $("#GET").click(function () { $.get("ProceseAjaxJson.ashx", "b=4", function (date) { var j = $.parseJSON(date); alert(j[2].CityName); }); }); $("#Post").click(function () { $.post("ProceseAjaxJson.ashx", { b: 5, date: '2014' }, function (date) { alert(date[0].CityName); },"json"); }); $("#Ajax").click(function () { $.ajax({ url:"ProceseAjaxJson.ashx", data:"ss=11", type:"get", success:function(date){ alert(date); }, error:function(date){ alert("出错了"); } }); }); }); </script> </head> <body> <input type="button" id="Getjson" value="Ajax获取Json数据" /> <input type="button" id="GET" value="Ajax的Get请求" /> <input type="button" id="Post" value="Ajax的Post请求" /> <input type="button" id="Ajax" value="Ajax的请求" /> <input type="text" id="txtjson" /> </body> </html>