【发布时间】:2010-05-25 03:28:09
【问题描述】:
我正在使用 Google App Engine (python sdk) 进行开发,我想使用 jQuery 发送 Ajax 请求来存储问题的答案。
将此数据发送到服务器的最佳方式是什么?目前我有:
function storeItem(question_id) {
var answerInputControl = ".input_answer_"+question_id;
var answer_text = $(answerInputControl).text();
$.ajax({
type: "POST",
url: "store_answer.html",
data: "question="+question_id,
success: function(responseText){
alert("Retrieved: " + responseText);
}
});
}
这需要一个问题 ID,并通过查询字符串将其提供给服务器。但是在服务器端,我无法访问我想要存储的答案控件的内容。如果没有 Ajax,我可以通过以下方式执行此操作:
class StoreAnswers(webapp.RequestHandler):
def post(self):
question_id = self.request.get("question_id")
answer_text = self.request.get("input_answer" + question_id)
但是当通过 Ajax 进行这个调用时,我的 answer_text 是空的。
- 我是否需要将此控件的内容作为 Ajax 请求数据的一部分发送?
- 是否将控件本身添加到查询字符串中?它的内容?内容可能有几百个字符长有关系吗?这是最推荐的做法吗?
- 如果将其作为查询字符串发送,那么转义内容以使恶意用户不会损害系统的最佳方法是什么?
【问题讨论】:
标签: jquery python ajax google-app-engine