zoukankan      html  css  js  c++  java
  • 发送Ajax请求获取JSON格式数据

    Aspx前端页面:

        <script type="text/javascript">
            $(function () {
    $.getJSON(
    "Ajax/TestAjax.ashx?_=" + Math.random(), function (json) { //发送请求 $('#result').html(json.result); $('#message').html(json.message); }); $('#<%=btnAdd.ClientID %>').click=function () { } }); </script>

    ajax一般处理程序页面:

    namespace WebFormTest.Ajax
    {
        /// <summary>
        /// $codebehindclassname$ 的摘要说明
        /// </summary>
        [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 11 11 22 22 22 33 33 33 "); // 制表转义符(空格效果) 换行转义符
                failedMessage.Append(@"11 11 11 22 22 22 33 33 33 ");
    string result = "结果信息";
    // \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; } } } }
  • 相关阅读:
    qt 问题及处理
    windows 依赖查看
    java基础知识
    Linux 相关
    OutLook中添加Exchange失败问题
    开源协议简介
    grail开发环境的搭建
    node+mongodb+WP构建的移动社交应用源码 分享
    INotifyPropertyChanged接口的详细说明
    WP8.1开发:后台任务详解(求推荐)
  • 原文地址:https://www.cnblogs.com/zxx193/p/3437877.html
Copyright © 2011-2022 走看看