Javascript 我想在发布数据后路由到新网页
我已经定义了这个路由,虽然render_模板以前对我有用,但我似乎不明白为什么web页面保留在现有页面上。我确信它会一直点击并处理,因为我返回了一个200,Ok,并在javascript端收到了回复。我甚至尝试将请求重定向为GET并允许GET渲染模板,但仍然没有成功。有什么想法吗 路线代码Javascript 我想在发布数据后路由到新网页,javascript,python,flask,post,Javascript,Python,Flask,Post,我已经定义了这个路由,虽然render_模板以前对我有用,但我似乎不明白为什么web页面保留在现有页面上。我确信它会一直点击并处理,因为我返回了一个200,Ok,并在javascript端收到了回复。我甚至尝试将请求重定向为GET并允许GET渲染模板,但仍然没有成功。有什么想法吗 路线代码 @app.route("/view", methods=["GET","POST"]) @cross_origin() def view_playl
@app.route("/view", methods=["GET","POST"])
@cross_origin()
def view_playlist():
global playlist_item
if request.method == 'POST':
playlist_item = request.get_json()
print("playlist POST")
return render_template('/view.html', result= playlist_item)
# return redirect(url_for('view_playlist'))
else:
print("This is a GET")
return render_template('/view.html', result= playlist_item)
# app.send_static_file("index.html", result= playlist_item)
javascript帖子如下
url = local + '/view'
fetch(url,{
headers: {
'Content-Type': 'application/json'
},
method: 'POST',
body:JSON.stringify(itemsPlaylist)
}).then(function(data) {
// location.replace(local + '/view.html');
})
查看代码无法想到任何明显的原因,但值得在其中打印响应,并将其放入catch块 您还可以使用finally进行路由
fetch(myRequest)
.then(function(response) {})
.catch(function(error) { console.error(error); })
.finally(function() { .. do the routing here });