发送Ajax请求获取JSON格式数据

Aspx前端页面:

    

 

ajax一般处理程序页面:

namespace WebFormTest.Ajax
{
    /// 
    /// $codebehindclassname$ 的摘要说明
    /// 
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class TestAjax : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //string json ="{\"Person\":[{\"Age\":18,\"Name\":\"张三\",\"Sex\":\"男\"}]}";

StringBuilder successMessage = new StringBuilder();
            StringBuilder failedMessage = new StringBuilder();
successMessage.Append(@"11\t11\t11\r\n22\t22\t22\r\n33\t33\t33\r\n"); // \t制表转义符(空格效果) \r\n换行转义符
            failedMessage.Append(@"11\t11\t11\r\n22\t22\t22\r\n33\t33\t33\r\n");
string result = "结果信息";
// \\r\\n转义后为\r\n在前端浏览器解析后为换行
string message = "发放失败:\\r\\n" + failedMessage.ToString() + "\\r\\n\\r\\n发放成功:\\r\\n" + successMessage.ToString();
string json = "{\"result\":\"" + result + "\",\"message\":\"" + message + "\"}"; //注意转义 context.Response.Write(json); } public bool IsReusable { get { return false; } } } }

 

转载于:https://www.cnblogs.com/zxx193/p/3437877.html

你可能感兴趣的:(发送Ajax请求获取JSON格式数据)