用ajax获取后台数据,返回json数据,怎么在前台使用?
用ajax获取后台数据,返回json数据,怎么在前台使用呢?
后台
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
if (dataType == "SearchCustomer") { int ID; if (Int32.TryParse(CustomerID, out ID)) { string s = GridComputer.GridCustomer.getCustomer(1, 1, ID); if (s == null) { context.Response.ContentType = "text/plain"; context.Response.Write("[{\"name\":无用户,\"id\":\"0\",\"company\":\"无用户\"}]"); } else { context.Response.Write(s); } } } |
前台
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
$(document).ready(function () { $("#Button3").click( function (SucCallback) { $.ajax( { type: "get", url: 'GridDatas.ashx', //后台处理程序 dataType: 'json', //接受数据格式 data: 'DataType=SearchCustomer&CustomerID=' + document.getElementById("Text3").value, //要传递的数据 success:SucCallback, error: function () { alert("error"); } }); }) }) |
参考代码
|
1
2
3
4
5
6
7
8
9
|
grid.getCustomer(1,2,function (data) { var list = '<p>' + tree_GridInfo._name + '的用户有</p><br>'; list += '<table id="customers"><tr><th>姓名</th><th>电话</th></tr> '; $.each(data, function (i, n) { list += '<tr onclick="showUser(' + 1 + ')"><td>'; list += n.name + '</td>' + '<td>' + n.company; list += '</td></tr>'; }); $("#SearchResult").html(list) |
=======================================================================================
context.Response.Write("{\"name\":无用户,\"id\":\"0\",\"company\":\"无用户\"}");
$(document).ready(function () {
$("#Button3").click(
function (SucCallback) {
$.ajax(
{
type: "get",
url: 'GridDatas.ashx', //后台处理程序
dataType: 'json', //接受数据格式
data: 'DataType=SearchCustomer&CustomerID=' + document.getElementById("Text3").value, //要传递的数据
function (dataJson) {
alert(dataJson.Name);
alert(dataJson.Id);
},
error: function () { alert("error"); }
});
})
})
用ajax获取后台数据,返回json数据,怎么在前台使用?的更多相关文章
- ajax获取后台传递的json数据
最近在使用JQuery的ajax方法时,需要返回的数据为json数据,在success返回中数据处理会根据返回方式不同会采用不同的方式来生成json数据.在$.ajax方法中应该是如何来处理的,简 ...
- ajax请求、servlet返回json数据
ajax请求.servlet返回json数据 1.方式一 response.setcontenttype("text/html;charset=utf-8"); response. ...
- jquery的ajax异步请求接收返回json数据
http://www.jb51.net/article/51122.htm jquery的ajax异步请求接收返回json数据方法设置简单,一个是服务器处理程序是返回json数据,另一种就是ajax发 ...
- ajax请求后台,返回json格式数据,模板!
添加一个用户的时候,需要找出公司下所有的部门,和相应部门下的角色,利用ajax请求,实现联动技术.将返回的json格式数据,添加到select标签下. <script type="te ...
- 使用jQuery解析JSON数据(由ajax发送请求到php文件处理数据返回json数据,然后解析json写入html中呈现)
在上一篇的Struts2之ajax初析中,我们得到了comments对象的JSON数据,在本篇中,我们将使用jQuery进行数据解析. 我们先以解析上例中的comments对象的JSON数据为例,然后 ...
- 如何用 ajax 连接mysql数据库,并且获取从中返回的数据。ajax获取从mysql返回的数据。responseXML分别输出不同数据的方法。
开讲前,先说下网上,大部分的关于这方面的博文或者其他什么的,就我自己的感觉,第一说得不详细,第二语言不能很好的被初学者了解. 我这篇博文的标题之所以用了三句,是为了方便其他人好查找: 这里介绍的方法有 ...
- 用jQuery的ajax请求一般处理程序返回json数据
1.web页面代码: 注意事项: dataType类型一定要写成json. 2.一般处理程序代码: 注意事项: ContentType类型写成"application/json"或 ...
- ajax调用后台webservice返回JSON字符
后台代码: [WebMethod] public static string LoginTest(string userCode, string password) { UserManageCente ...
- Php如何返回json数据,前后端分离的基本解决方案
php返回json,xml,JSONP等格式的数据 返回json数据: header('Content-Type:application/json; charset=utf-8'); $arr = a ...
- Php如何返回json数据
php返回json,xml,JSONP等格式的数据 返回json数据: header('Content-Type:application/json; charset=utf-8'); $arr = a ...
随机推荐
- 26. linux查看端口占用情况
linux系统下,查看端口占用情况的命令:lsof -i[root@www ~]# lsof -i
- Mysql存储过程调用
mysql存储过程实例教程 发布时间:2014-04-09编辑:JB01 这篇文章主要介绍了mysql存储过程的使用方法,mysql存储过程实例教程,有需要的朋友参考下. 1.1create p ...
- jsp页面无法解析EL表达式
从eclipse迁移到idea,真是各种被坑. 今天遇到的jsp无法解析EL,页面直接就显示${xxx}好坑爹 Root cause:idea生成的web.xml 的web-app版本居然是2.3,2 ...
- [delphi]极域学生端解除键盘鼠标锁定退出全屏广播-强制窗口化-源代码
v2.0 2015-07-11 更新了V2.0 版本 发布在吾爱破解论坛 欢迎下载使用 http://www.52pojie.cn/thread-382769-1-1.html ---------- ...
- 搭建DAO层和Service层代码
第一部分建立实体和映射文件 1 通过数据库生成的实体,此步骤跳过,关于如何查看生成反向工程实体类查看SSH框架搭建教程-反向工程章节 Tmenu和AbstractorTmenu是按照数据库表反向工程形 ...
- google垂直搜索结果
佰年金融 所谓“垂直”很干净地分离出来,而不是在谷歌算作有机列表的结果,但该行已开始模糊.例如,现在许多视频结果似乎是直接整合为有机(万SERP的例子).我治疗的新的“有深度的文章”作为一个垂直的结果 ...
- Jquery Mobile示例
http://www.w3school.com.cn/jquerymobile/jquerymobile_examples.asp
- Android_Fragment(碎片)知识点讲解
今天我们来了解下Android 中的fragment(碎片)这个东西. Fragment 从英文翻译而言是碎片,片段的意思.那么这个东西是什么,在Android 中有什么用呢? 一.概念 Fragme ...
- android_demo之生成颜色布局
前面学习了动态生成表格,不单单是要动态生成控件,也同时生成一个事件. 接下来用个小小栗子去了解这个知识点. <LinearLayout xmlns:android="http://sc ...
- CentOS6.3连接Xshell出现的问题(连接失败--需要设置ONBOOT=“yes”,开启网卡驱动)
小白记录: 安装Xshell之后连接CentOS6.3的baseService版本,连接不上, service network restart 只有两个OK, 百度查找资料后--得到结论:网卡设置之 ...