Ajax回调返回0

in last 2 days I tried to solve my problem. Now I need help. My task is very simple. Jquery ajax request posts a user name and a password to server, where is python framework "Flask". I did very simple example, but it still doesn't work.

ajax:

$.ajax({
                    url: "http://localhost:5000/login",
                    type: "POST",
                    dataType: "json",
                    data: values, //(json with username and password)
                    complete:function(response){
                        console.log(response);
                    }

                });

I tried to rewrite success and error function, but result is the same. Everything returns:

Object { readyState=0, status=0, statusText="error", more...}

Flask implementation:

@app.route("/login", methods=["GET", "POST"])
def login_page():

    return jsonify(redirect="index.html")

Headers:

response:

Content-Length  30
Content-Type    application/json
Date    Sun, 20 Oct 2013 09:50:19 GMT
Server  Werkzeug/0.9.3 Python/2.7.3
Set-Cookie  session=eyJfaWQiOnsiIGIiOiJOakkwTUdVM01HVXhNR0prWmpka05qQXlPRGcwT1dWbFlUQmhPRGRpT0RrPSJ9fQ.BUU42w.FDnVp15DxEsMPP_TsOpq8OzzU5I; HttpOnly; Path=/

request:

Accept  application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language cs,en-us;q=0.7,en;q=0.3
Cache-Control   no-cache
Connection  keep-alive
Content-Length  102
Content-Type    application/x-www-form-urlencoded; charset=UTF-8
Host    127.0.0.1:5000
Origin  http://localhost
Pragma  no-cache
Referer http://localhost/login.html
User-Agent  Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0

I tried to return a redirection, and console network log shows me this returning, but I have found the ajax doesn't redirect (https://stackoverflow.com/a/17256609/2107985). Every time console.log from ajax function shows me "error", although there is 200 OK.

By manually typing link: http://localhost:5000/login to the browser, it returns json normally.

Your request says Origin http://localhost but the URL you are requesting is http://localhost:5000/login.

Your console should be giving you the warning:

Origin http://localhost is not allowed by Access-Control-Allow-Origin.

Your ability to read the data is limited by the same origin policy. You either need to use the same origin for both requests or circumvent it.