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");
}
});
}
下面是我的蟒蛇应用程序副本文件
@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)
下面是我的存根索引.html文件
<div class="tweet">
<div class="data">
<button onclick="display_tweet()">display a new tweet</button>
<div id="fulltextt"></div>
</div>
我继续得到一个空的json,后端有500个内部错误,如下所示。有人能帮忙吗
{}
127.0.0.1 - - [04/Feb/2020 23:02:07] "POST /get_tweet HTTP/1.1" 500 -