我试图查询包含关于“票”使用jQuery's .ajax()方法信息的数据库...自定义HTTP响应,C#和.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 scrip库? json在这里是一个很好的关键词。否则,将数据转换为xml,将其作为文本发送并解析到客户端。 – user492238 2011-04-05 14:16:00