下面是我的functions.js文件
var count = 1;
// get a tweet from backend
function display_tweet(){
var req = {
"index": count
}
.ajax({
type: "POST",
url: "get_tweet",
data: '{"id":"' + count+'}',
dataType: "json",
success: function(data) {
alert(data.d);
},
error: function(data){
alert("fail");
}
});
}
下面是我的python app.py文件
@app.route('/get_tweet',methods = ['POST'])
def get_tweet():
#user_agent_received = request.get_json()
#print("request is ",request.form)
print("request ",request.get_json())
global data_dict
print(data_dict)
input_map = dict(request.form.to_dict())
print(input_map)
index=input_map['index']
index=int(str(index))
final_dic={}
final_dic["text"]=data_dict[index]["tweet"]["full_text"]
return json.dumps(final_dic)
下面是我的index.html文件中的存根
<div class="tweet">
<div class="data">
<button onclick="display_tweet()">display a new tweet</button>
<div id="fulltextt"></div>
</div>
我不断在后端得到一个带有500内部错误的空json,看起来像这样。请有人帮忙
{}
127.0.0.1 - - [04/Feb/2020 23:02:07] "POST /get_tweet HTTP/1.1" 500 -