【问题标题】:How to redirect one domain to another through ajax and python tornado?如何通过 ajax 和 python tornado 将一个域重定向到另一个域?
【发布时间】:2016-02-25 05:41:52
【问题描述】:

我对一个正在运行龙卷风服务器的域进行了 ajax 调用,

  $.ajax({
      url: "http://test.example.com/setvalhandler",
      type:'POST',
      cache: false,
      data: {rsp:JSON.stringify(response)},
      success: function(resp) {
      },
      error: function() {

      }
  });

我有一个带有“/setvalhandler”处理程序的龙卷风服务器。我已经为跨域请求设置了标头。最后我想重定向到龙卷风中的不同处理程序。但我在浏览器控制台中收到“302 Found”和“Cross-Origin Request Blocked”警告。

Python 代码:

class SetvalHandler(tornado.web.RequestHandler):
    def set_default_headers(self):       
        self.set_header("Access-Control-Allow-Origin", "http://www.example.com/") # request origin domain
    def post(self):
        self.redirect("/newhadler")

【问题讨论】:

标签: python ajax tornado


【解决方案1】:

我建议发送您需要重定向到的网址作为响应。然后使用 window.redirect 或类似的东西从前端重定向到新页面。

PS:后端也有可能。但我认为从前端重定向更容易。

【讨论】:

  • 谢谢 Swetabh。但出于安全原因,我有意从后端尝试
  • 您在此特别要解决的安全问题是什么?
猜你喜欢
  • 2014-09-14
  • 1970-01-01
  • 2014-08-28
  • 2015-12-02
  • 2020-05-04
  • 2015-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多