用ajax获取后台数据,返回json数据,如何在前台使用呢
用ajax获取后台数据,返回json数据,怎么在前台使用呢?
用ajax获取后台数据,返回json数据,怎么在前台使用呢?
后台
前台
参考代码
用ajax获取后台数据,返回json数据,怎么在前台使用呢?
后台
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); }
}
}
前台
$(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"); }
});
})
})
参考代码
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);
- 1替年度评选活动添加倒计时功能
- 2如何将部门和子部门在一个listbox中显示
- 3ajax异步登陆页面无法跳转解决办法
- 4小弟我有一共享打开数据库类,第一次打开时没有异常,以后打开就出现异常,请教高手怎样纠正,多谢
- 5asp.net word操作有关问题
- 6web api怎么显示序列化datatable
- 7Dapper小型ORM的使用(任意吐槽下公司)
- 8大三在校生的传智120天的1200小时.net(十三)关于Response.Redirect跟Server.Execute的区别
- 9项目中摘引CodeSmith相关的DLL
- 10net 调用oracle存储过程(PLS-00306),该怎么解决
- 上一篇:C#靠山接受post过来的值
- 下一篇:字符串替换*有关问题。求指导
文章评论
相关解决方案