tornadoweb Access-Control-Allow-Origin jquery POST

时间:2013-07-31 13:45:19

标签: jquery post tornado cors

我想通过jQuery使用POST请求启用CORS请求到我的处理程序。龙卷风请求和jquery下面

class BaseHandler(tornado.web.RequestHandler):
    def set_default_headers(self):
        self.set_header('Access-Control-Allow-Origin', '*')
        self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS')
        self.set_header('Access-Control-Max-Age', 1000)
        #self.set_header('Access-Control-Allow-Headers', 'origin, x-csrftoken, content-type, accept')
        self.set_header('Access-Control-Allow-Headers', '*')
        self.set_header('Content-type', 'application/json')

但是在打电话之后:

$.ajax({
            type: 'POST',
            url: _url,      
            /*      
            beforeSend : function(x) {
                if (x && x.overrideMimeType)
                    x.overrideMimeType("application/j-son;charset=UTF-8");
            },*/
            beforeSend: function ( xhr ) {
                xhr.setRequestHeader('Content-Type', 'application/json');
                xhr.setRequestHeader('Access-Control-Request-Method', 'POST');
                xhr.setRequestHeader('Access-Control-Request-Headers', 'X-Requested-With');
                xhr.withCredentials = true;
            },  
            data : _data,            
            dataType: 'json',
            contentType: 'application/json',
            success:  function (data) {
                alert(data);
            },
            error: function (err) {
                console.log("ajax response: "+resp+" json="+JSON.stringify(resp));
            }
        });

我发送: enter image description here

我收到:重新加载页面以获取"我的帖子网址来到这里"。 抓住哪个想法?

0 个答案:

没有答案