【问题标题】:Sending GET query using Javascript to GAE to redirect to another page使用 Javascript 向 GAE 发送 GET 查询以重定向到另一个页面
【发布时间】:2013-02-04 22:32:17
【问题描述】:

在 GAE (Python) 上,我尝试从本地 javascript 发送 GET 请求,并在收到请求后重定向到另一个页面。这是我的代码:

发送 POST 的本地 Javascript:

$.get("/editor");

GAE 上的 Python

class Editor(webapp2.RequestHandler):
    def get(self):
        template = jinja_environment.get_template('index.html')
        self.response.out.write(template.render())

app = webapp2.WSGIApplication([('/', StartScreen), ('/editor', Editor)],
                              debug=True)

我可以在 url 栏中输入 url /editor,它会带我到那里。为什么我的 javascript GET 请求没有激活编辑器处理程序并打开 /editor?

【问题讨论】:

  • 请求会发生什么?你有错误吗?您的代码是否在页面成功响应之前重定向?

标签: python google-app-engine get


【解决方案1】:

我不确定我是否理解这个问题,但还是试试看: 当前使用jQuery.get() 的方式应该调用服务器但丢弃响应,因此您将在浏览器中看不到任何内容。 你至少想做:

$.get("/editor", function(response) { 
     document.location.href = 'another page'; 
});

another page 是您要重定向到的位置。然后这仍然会丢弃您从服务器获得的内容。 (response 将是一些 HTML ......我不确定你想如何从中获取位置。)所以我想知道一个简单的 HTML 链接是否能满足你的要求。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多