国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jQuery+ajax+asp.net獲取Json值的方法

2019-11-20 09:45:16
字體:
來源:轉載
供稿:網友

本文實例講述了jQuery+ajax+asp.net獲取Json值的方法。分享給大家供大家參考,具體如下:

<html xmlns="http://www.w3.org/1999/xhtml"><head>  <title>jQueryAjaxJson取值示例</title>  <script type="text/javascript" src="Scripts/jquery-1.4.4.min.js"></script>  <script type="text/javascript">    $(document).ready(function () {      $("#Button1").click(function () {        $.ajax({          url: 'AjaxQuery.aspx',          type: 'GET',          dataType: 'json',          timeout: 1000,          cache: false,          beforeSend: LoadFunction, //加載執行方法          error: erryFunction, //錯誤執行方法          success: succFunction //成功執行方法        })        function LoadFunction() {          $("#ddd").html('加載中...');        }        function erryFunction() {          alert("error");        }        function succFunction(tt) {          $("#ddd").html('');          var json = eval(tt); //數組          $.each(json, function (index, item) {            //循環獲取數據            var name = json[index].Name;            var age = json[index].Age;            var sex = json[index].Sex;            $("#ddd").html($("#ddd").html() + "<br>" + name + " - " + age + " - " + sex + "<br/>");          });        }      });    })  </script></head><body>  <input type="button" id="Button1" value="獲取json數據" />  <span id="ddd"></span></body></html>
//Ajax Post Textfunction savedata(tempid) {  var tid = $('#hidtemplate').attr('value');  var desc = $("#contentdiv").html();  var num_iid = $("#num_iidArr").attr('value');  var num_iid2 = $("#num_iidArr001").attr('value'); //發布頁面  var topsvalue = $("#tops").attr('value');  if (num_iid != "" && num_iid2 != "") {    $.ajax({      url: 'TabBaoHandler.ashx',      type: 'POST',      data: 'type=3&num_iid=' + num_iid2 + '&tid=' + tid + '&desc=' + desc + '&top_session=' + topsvalue,      dataType: 'text',      timeout: 20000,      cache: false,      //async: false, //同步      beforeSend: LoadFunction, //加載執行方法      error: erryFunction, //錯誤執行方法      success: succFunction //成功執行方法    })    function LoadFunction() {      showLoad("正在運行中...");    }    function erryFunction() {      $("#contentdiv").html("<p style=/"padding:5px/"><img src=/"images/error.png/" />sorry,提交失敗</p>");      closeLoad();    }    function succFunction(tt) {      closeLoad();      $("#contentdiv").show().html(tt);    }  } else {    alert("請選擇后再操作");  }}
using System;//新增using System.Web.Script.Serialization;using System.Collections.Generic;public partial class AjaxQuery : System.Web.UI.Page{  protected void Page_Load(object sender, EventArgs e)  {    if (!IsPostBack)    {      List<Student> list = new List<Student>();      Student c = new Student();      c.Name = "張三";      c.Age = 23;      c.Sex = "男";      list.Add(c);      Student cc = new Student();      cc.Name = "李四";      cc.Age = 25;      cc.Sex = "男";      list.Add(cc);      Student ccc = new Student();      ccc.Name = "李玲";      ccc.Age = 25;      ccc.Sex = "女";      list.Add(ccc);      Response.ContentType = "application/json";      Response.Write(new JavaScriptSerializer().Serialize(list));////這個很關鍵,否則error      Response.End();    }  }  public struct Student  {    public string Name;    public int Age;    public string Sex;  }}

PS:這里推薦幾款本站的json格式數據在線操作工具供大家免費使用,相信在以后的開發中可以派上用場:

在線JSON代碼檢驗、檢驗、美化、格式化工具:
http://tools.VeVB.COm/code/json

在線XML/JSON互相轉換工具:
http://tools.VeVB.COm/code/xmljson

C語言風格/HTML/CSS/json代碼格式化美化工具:
http://tools.VeVB.COm/code/ccode_html_css_json

json代碼在線格式化/美化/壓縮/編輯/轉換工具:
http://tools.VeVB.COm/code/jsoncodeformat

更多關于jQuery相關內容感興趣的讀者可查看本站專題:《jquery中Ajax用法總結》、《jQuery表格(table)操作技巧匯總》、《jQuery拖拽特效與技巧總結》、《jQuery擴展技巧總結》、《jQuery常見經典特效匯總》、《jQuery動畫與特效用法總結》、《jquery選擇器用法總結》及《jQuery常用插件及用法總結

希望本文所述對大家jQuery程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 佛教| 陕西省| 安乡县| 航空| 萨迦县| 弥勒县| 随州市| 岑溪市| 都兰县| 克什克腾旗| 毕节市| 衢州市| 祁阳县| 贵港市| 伊春市| 南通市| 改则县| 集安市| 囊谦县| 汶上县| 吴忠市| 锡林浩特市| 团风县| 延川县| 辽源市| 阳春市| 格尔木市| 阿荣旗| 鸡泽县| 修水县| 宜阳县| 阿拉善右旗| 阿城市| 会昌县| 焉耆| 苗栗市| 樟树市| 于都县| 濉溪县| 北海市| 南安市|