用Jquery访问Handler.ashx并返回Json
来源:互联网 发布:vr funhouse 源码下载 编辑:程序博客网 时间:2024/06/04 19:09
Default.html前台页面代码
<html xmlns="http://www.w3.org/1999/xhtml" ><head> <title>无标题页</title> <script. type="text/javascript" src="js/jquery-1.2.1.pack.js"></script></head><script. type="text/javascript"> $(document).ready(function (){ $("#btnOK").click(function (){ $.getJSON( "Handler.ashx", {}, function(json){ $("#list").append("<li>id:"+json.EmployeeId+"|Name:"+json.EmployeeName+"|年龄:"+json.EmployeeInfo[0]+"|身高:"+json.EmployeeInfo[1]+"|体重:"+json.EmployeeInfo[2]+"</li>"); } ) }) })</script><body> <input id="btnOK" value="加载数据" type="button"/> <ul id="list"> </ul></body></html>
Handler.ashx服务器端处理请求的代码
<%@ WebHandler Language="C#" Class="Handler" %>using System;using System.Web;using System.Web.UI.HtmlControls;using System.Runtime.Serialization;using Newtonsoft.Json;public class Handler : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Write(ReturnResult()); } public string ReturnResult() { Employee employee = new Employee(); employee.EmployeeId = 1; employee.EmployeeName = "yang"; employee.EmployeeInfo = "25,170cm,55kg".Split(','); string jsonstr = JavaScriptConvert.SerializeObject(employee); return jsonstr; } public bool IsReusable { get { return false; } } class Employee { public int EmployeeId; public string EmployeeName; private string[] employeeInfo; public string[] EmployeeInfo { get { return employeeInfo; } set { employeeInfo = value; } } }}
http://blog.csdn.net/zj1103/article/details/2822215
注意:
JavaScriptConvert.SerializeObject:可以序列化对象或者集合(eg:List等)
Newtonsoft.Json的版本是
下载地址:http://download.csdn.net/detail/ze_lin_huang/5044423
- 用Jquery访问Handler.ashx并返回Json
- 用Jquery访问WebService并返回Json
- AJAX提交到Handler.ashx一般处理程序返回json数据
- AJAX提交到Handler.ashx一般处理程序返回json数据 (字符串拼接方式)
- HTTP访问 并得到返回结果 JSon
- Jquery+ashx+json 绑定数据
- jquery ajax json ashx实用技巧
- jquery访问ashx文件示例
- jquery跨域访问ashx
- Jquery Ajax 调用 ashx 返回结果
- ajax 解决方案(Newtonsoft.Json +jQuery +ashx)
- jquery, json与ashx的完美结合
- jquery ajax,ashx,json用法小结
- jquery ajax,ashx,json用法小结
- jquery, json与ashx的完美结合
- Jquery+Ajax+Json+ashx生成表
- jquery ajax,ashx,json的用法总结
- jquery, json与ashx的完美结合
- Android自定义TextView 达到倾斜效果
- spring jar包结构
- ListView中的一些属性介绍
- 大端(Big Endian)与小端(Little Endian)详解
- iphone开发笔记3
- 用Jquery访问Handler.ashx并返回Json
- 为表设计器构造筛选字符串
- MFC CInternetSession OpenUrl 下载文件 防止异常
- FusionCharts图表常见问题及解决方法(一)
- hdu 1004 trie树
- struts2 rest插件
- std::map 的删除和插入效率
- iOS开发之详解剪贴板
- 鹤林全集·梦语铭心 | 第一篇——智慧人生(上)