我試圖查詢包含關於「票」使用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