在谷歌应用发动机(python sdk)中,我会利用 j,发出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);
}
});
}
这是一个问题,通过电梯向服务器提供。 但是,在服务器方面,我无法查阅我想要储存的答案控制的内容。 如果没有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是空的。
- Do I need to send the contents of this control as part of the data with the Ajax request?
- Do I add the control itself to the query string? Its contents? Does it matter that the content might be a few hundred characters long? Is this the most-recommended practice?
- If sending it as a query string, what s the best way to escape the content so that a malicious user doesn t harm the system?