【发布时间】:2011-04-05 14:10:37
【问题描述】:
我正在尝试使用jQuery's .ajax() 方法查询包含“票证”信息的数据库...
$.ajax({
type: 'GET',
url: 'Preview.ashx',
data: 'ticketID=' + ticketID,
success: function (data) {
// 'data' should be a row from the database, so it should be like an
// array that contains each column of the row
// do stuff with this data
}
});
...所以一切正常。我在使用 data 变量时遇到问题。在服务器端,我确实...
// get the ticket ID from the POST parameter
int ticketID = context.Request["ticketID"] != null ? Convert.ToInt32(context.Request["ticketID"]) : -1;
if (ticketID >= 0) {
// grab the data from the database, getInfo() will retrieve the row
// in the DB that corresponds to the ticket ID given, returning an
// ArrayList with all of the information
ArrayList theTicket = getInfo(context, ticketID);
// now, I need to somehow return this information so that I could deal with it
// in the 'success' callback function above
return;
} else {
// something went wrong with the 'newTicket' POST parameter
context.Response.ContentType = "text/plain";
context.Response.Write("Error with 'ticketID' POST parameter. \n");
return;
}
return;
我已经对此进行了足够的调试,以确保 ArrayList 包含正确的信息。现在我只需要退货。
我该怎么做?我将如何返回 ArrayList 中的数据?是否可以构造响应以便我可以在回调函数中执行data.ID、data.otherColumnName 等...以访问不同的字段?
【问题讨论】:
-
是否可以使用任何 java 脚本库? json 将是一个很好的关键字。如果没有,将数据转成xml,以文本形式发送,在客户端解析。
标签: c# asp.net ajax json httpresponse