<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestWcf.aspx.cs" Inherits="WebApplication1.TestWcf" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input type="button"  id="send"  value="请求" />
        <div id="resText">
        </div>
        
    </div>
    </form>
</body>
</html>
<script src="Scripts/jquery-1.10.2.min.js"></script>
<script src="Scripts/jquery-1.10.2.js"></script>
<script type="text/javascript"  >
  
    $(function () {
        $('#send').click(function () {
            //alert("111");
           
            //获取参数
            var PostParam = {
                'UserInfo': JSON.stringify({
                    'Name': escape("花千骨"),  //  'Name': escape($("#Name").val()),
                    'NickName':"dddd",
                    'Email':"moloic@163.com",
                    'CreateTime': "2015-12-12"
                   
                })
            }
            $.ajax({
                type: "GET",  //POST
                url: "UserInfoHandler.ashx",
                data: PostParam,
                dataType: "json",
                success: function (data) {
                  //  alert("sss");
                  //  debugger;
                    $('#resText').empty();   //清空resText里面的所有内容
                    var html = '';
                    $.each(data, function (commentIndex, comment) {
                        html += '<div class="comment"><h6>' + comment['Name']
                                  + ':</h6><p class="para"' + comment['Email']
                                  + '</p></div>';
                    });
                    $('#resText').html(html);
                }
            });
        });
    });
</script>

---------------------------------------------后台处理-----------------------------------------------------------------------------------

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebApplication1
{
    /// <summary>
    /// UserInfoHandler 的摘要说明
    /// </summary>
    public class UserInfoHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write(getUserList( context));
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
        public string getUserList(HttpContext context)
        {
           
            TestModel.UserInfo UserInfo = new TestModel.UserInfo();
            //获取参数
            UserInfo = (TestModel.UserInfo)JsonConvert.DeserializeObject(context.Request["UserInfo"].ToString(), typeof(TestModel.UserInfo));
            UserInfo.Name=  HttpUtility.UrlDecode(UserInfo.Name);
           
      
            List<TestModel.UserInfo> userinfoList = new List<TestModel.UserInfo>();
            //加载数据
            try
            {
                ServiceReference1.Service1Client service = new ServiceReference1.Service1Client();
                IList<TestModel.UserInfo> ilist = new List<TestModel.UserInfo>();
                ilist = service.getUserInfoData(UserInfo);
                userinfoList = IListToList<TestModel.UserInfo>(ilist);
            }
            catch (Exception ex)
            {
                userinfoList = null;
            }
            return JsonConvert.SerializeObject(userinfoList);
            
        }
        /// <summary>
        /// ILIST 转换LIST 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list"></param>
        /// <returns></returns>
        public List<T> IListToList<T>(IList<T> list)
        {
            T[] array = new T[list.Count];
            list.CopyTo(array, 0);
            return new List<T>(array);
        }
    }
}

ajax 以json 的形式来传递返回参数的实例的更多相关文章

  1. 当页面是本地页面时,通过ajax访问tomcat里的action,传递的参数在action里并不能识别

    当页面是本地页面时,通过ajax访问tomcat里的action,传递的参数在action里并不能识别,这个问题困扰了我不少时间. 在测试时发现此问题

  2. 【转】AJAX中JSON数据的返回处理问题

    AJAX处理复杂数据时,便会使用JSON格式.常用在对数据库的数据查询上.在数据库查询到数据后,便可在处理页面直接将数据转为JSON格式,然后返回. 本篇主要讨论:jQuery中,JSON数据在AJA ...

  3. 关于使用Ajax请求json数据,@RequestMapping返回中文乱码的几种解决办法

    一.问题描述: 使用ajax请求json数据的时候,无论如何返回的响应编码都是ISO-8859-1类型,因为统一都是utf-8编码,导致出现返回结果中文乱码情况. $.ajax({ type:&quo ...

  4. js进阶ajax读取json数据(ajax读取json和读取普通文本,和获取服务器返回数据(链接)都是一样的,在url处放上json文件的地址即可)

    js进阶ajax读取json数据(ajax读取json和读取普通文本,和获取服务器返回数据(链接)都是一样的,在url处放上json文件的地址即可) 一.总结 ajax读取json和读取普通文本,和获 ...

  5. ajax请求(二),后台返回的JSon字符串的转换

    ajax请求,json的转换 $.ajax({ url : "../folder/isExistAddFolder.do?t="+new Date(), type : 'POST' ...

  6. SpringMvc+ajax 实现json格式数据传递

    传JSON对象 前端 function test () { var param = {username : "yitop"}; $.ajax({ timeout : 20000, ...

  7. ajax、json一些整理(2)

    <script type="text/javascript"> $(document).ready(function(){ $("#btn").cl ...

  8. ajax请求json数据跨域问题(转)

    一.后台代理技术 由服务器端向跨域下的网站发出请求,再将请求结果返回给前端,成功避免同源策略的限制. 具体操作如下: 1.在localhost:81/a.html中,向同源下的某个代理程序发出请求 $ ...

  9. Django-choices字段值对应关系(性别)-MTV与MVC科普-Ajax发json格式与文件格式数据-contentType格式-Ajax搭配sweetalert实现删除确认弹窗-自定义分页器-批量插入-07

    目录 models 字段补充 choices 参数/字段(用的很多) MTV与MVC模型 科普 Ajax 发送 GET.POST 请求的几种常见方式 用 Ajax 做一个小案例 准备工作 动手用 Aj ...

随机推荐

  1. Python supprocess模块

    当我们需要调用系统的命令的时候,最先考虑的os模块.用os.system()和os.popen()来进行操作.但是这两个命令过于简单,不能完成一些复杂的操作,如给运行的命令提供输入或者读取命令的输出, ...

  2. Spring 使用注解注入 学习(四)

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  3. Go语言语法说明

    Go语言语法说明 go语言中的go func(){}() 表示以并发的方式调用匿名函数func 深入讲解Go语言中函数new与make的使用和区别 前言 本文主要给大家介绍了Go语言中函数new与ma ...

  4. Android三角标签View:TriangleLabelView

     Android三角标签View:TriangleLabelView 在一些商城.产品推销类APP中,如淘宝.京东.电影门票销售.商品降价促销这类的APP,常常会在其APP中看到,某些商品的左上角 ...

  5. mysql中有关树的函数

    用mysql客户端在库中建立函数queryOrgChildren(查找子节点)和queryOrgLevel(查看当前节点在树中的级别):DROP FUNCTION IF EXISTS `queryOr ...

  6. ChargeSystem——One,Two,Three

    在提高班,大家都知道"ChargeSystem",中文名字为"机房收费系统". 在提高班,米老师的经典语录中有这么一句话:"学习是须要不断重复的过程. ...

  7. HDUPhysical Examination(贪心)

    HDUPhysical Examination(贪心) 题目链接 题目大意:给N个队列,每一个队列在0时刻体检的时候完毕时间是ai.假设超过t(s),那么就是ai + t∗bi.问如何组合才干用最短的 ...

  8. UVa 489 Hangman Judge(字符串)

     Hangman Judge  In ``Hangman Judge,'' you are to write a program that judges a series of Hangman gam ...

  9. LeetCode 203. Remove Linked List Elements (移除链表中的项)

    Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --& ...

  10. Java 实现的断点下载

    该断点下载可应用于浏览器或者迅雷等下载工具的下载,实现方式有多种多样的,本文仅仅研究了单线程的下载.迅雷等下载工具会自己主动将下载资源分块并记录每块的起始位置,然后依据系统性能.起多线程下载. 1. ...