如果用戶想要上傳的文件已經在他的文件列表中(他將覆蓋),我正在使用Javascript來詢問我們的應用程序(位於Google App Engine中)。如何響應XMLHttpRequest
我知道如何發送請求,但是如何使用Python創建來自服務器的響應?
這是請求:
var req = new XMLHttpRequest();
req.open('POST', 'https://safeshareapp.appspot.com/upload', async);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", body.length);
req.setRequestHeader("Connection", "close");
if (async) {
req.onreadystatechange = function() {
if(req.readyState == 4 && req.status == 200) {
var response = null;
try {
response = JSON.parse(req.responseText);
} catch (e) {
response = req.responseText;
}
callback(response);
}
}
}
// Make the actual request
req.send(body);
正如你看到的,我們從請求得到responseText的後一切都已經好了,但我的問題是我們如何填補在服務器端的responseText場??
您使用什麼語言,服務器端?說,你正在使用PHP。然後,你可以使用:'<?php ...........; echo json_encode($ variable_to_serialize); ?>' –
我們正在使用Python – c4sh