JQuery.getJSON 从aspx页面返回JSON数据 . 2012-01-05 12:44:02| 分类: asp.net |举报|字号 订阅1. 发送请求的WebForm1.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Benq.Flower.WebAdmin.Module.WebForm1" %>
view plaincopy to clipboardprint?<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Benq.Flower.WebAdmin.Module.WebForm1" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Benq.Flower.WebAdmin.Module.WebForm1" %>
2. 提供数据的WebForm2.aspxview plaincopy to clipboardprint?public partial class WebForm2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string callback = Request.QueryString["jsoncallback"]; string data = "{\"title\": \"Recent Uploads tagged cat\",\"link\": \"http://www.sina.com.cn\",\"items\": [{\"title\": \"Russell 003\",\"color\": \"red\"},{\"title\": \"Cat [07.04.11]\",\"color\": \"yellow\"}]}"; string result = string.Format("{0}({1})", callback, data); Response.Expires = -1; Response.Clear(); Response.ContentEncoding = Encoding.UTF8; Response.ContentType = "application/json"; Response.Write(result); Response.Flush(); Response.End(); } } view plaincopy to clipboardprint?public partial class WebForm2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string callback = Request.QueryString["jsoncallback"]; string data = "{\"title\": \"Recent Uploads tagged cat\",\"link\": \"http://www.sina.com.cn\",\"items\": [{\"title\": \"Russell 003\",\"color\": \"red\"},{\"title\": \"Cat [07.04.11]\",\"color\": \"yellow\"}]}"; string result = string.Format("{0}({1})", callback, data); Response.Expires = -1; Response.Clear(); Response.ContentEncoding = Encoding.UTF8; Response.ContentType = "application/json"; Response.Write(result); Response.Flush(); Response.End(); } } public partial class WebForm2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string callback = Request.QueryString["jsoncallback"]; string data = "{\"title\": \"Recent Uploads tagged cat\",\"link\": \"http://www.sina.com.cn\",\"items\": [{\"title\": \"Russell 003\",\"color\": \"red\"},{\"title\": \"Cat [07.04.11]\",\"color\": \"yellow\"}]}"; string result = string.Format("{0}({1})", callback, data); Response.Expires = -1; Response.Clear(); Response.ContentEncoding = Encoding.UTF8; Response.ContentType = "application/json"; Response.Write(result); Response.Flush(); Response.End(); } } 注意返回数据的格式 string.Format("{0}({1})", callback, data)