1 回答

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超4個(gè)贊
它的發(fā)生是因?yàn)槟恼谡{(diào)用更改 Ajax 請求(XMLHttpRequest)內(nèi)部 HTML 的路由,因此您有兩個(gè)選擇,第一個(gè)是更改 HTML 以響應(yīng)如下:
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
document.write(xhr.responseText);
}
}
// or using query(its better to me)
$.ajax({
type: "POST",
contentType: 'application/json',
url: "/",
data: {audio_data: blob}
success:function(response){
document.write(response);
}
});
另一種是做API,不需要調(diào)用render_template,只需要在index函數(shù)中返回resultsentence(這個(gè)result需要是dict格式)
@app.route("/", methods=['POST', 'GET'])
def index():
if request.method == "POST":
#the image logic...
return make_response(resultsentence)
else:
return render_template("index.html")
這樣,您將需要使用 javascript 處理前端的響應(yīng)
添加回答
舉報(bào)