用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);
...全文
相关推荐
前台ajax与后台json传递
解决从前台到后台数据传输的详细代码及注释
json的基本传值方式(从前台到后台,再从后台到前台)
自己因为被json传值累得十分痛苦,所以痛定思痛,在实现了一个基本的传值方式后,在此上传资源!下载用过的朋友请多多指出不恰当的地方!
基于ajax后台返回的数据为空前台显示出现undefined的解决方法
今天小编就为大家分享一篇基于ajax后台返回的数据为空前台显示出现undefined的解决方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
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.Respon
jQuery中ajax请求后台返回json数据并渲染HTML的方法
今天小编就为大家分享一篇jQuery中ajax请求后台返回json数据并渲染HTML的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧


