Javascript 登录后无法重定向到index.html页面

Javascript 登录后无法重定向到index.html页面,javascript,python,html,python-2.7,basehttpserver,Javascript,Python,Html,Python 2.7,Basehttpserver,我的客户端应用程序首先从login.html页面获取用户ID和密码,然后在按下“登录”按钮时,运行一个函数“display()”,从输入字段中存储ID和密码,并将其发送到服务器。服务器批准登录ID和密码,并尝试发送index.html页面。但是我无法发送index.html页面。可能是我的HTML代码或服务器端缺少某些内容 我的HTML(引导)代码是 登录链接 JavaScript“Display()”函数: <script> function Disp

我的客户端应用程序首先从login.html页面获取用户ID和密码,然后在按下“登录”按钮时,运行一个函数“display()”,从输入字段中存储ID和密码,并将其发送到服务器。服务器批准登录ID和密码,并尝试发送index.html页面。但是我无法发送index.html页面。可能是我的HTML代码或服务器端缺少某些内容

我的HTML(引导)代码是


登录链接
JavaScript“Display()”函数:

        <script>

    function Display(){
                var ID = document.getElementById("user_id").value;
                var passwrd = document.getElementById("password_id").value;
                var login = "/login:" + ID + "-" + passwrd + "--" ;

                var http = new XMLHttpRequest();
        http.open("GET", login, true); 
        http.onreadystatechange = function() {          if(http.readyState == 4 && http.status == 200) {
               var data = http.responseText;
                        if (data=="0"){
            document.getElementById("info_id").innerHTML =  "wrong password";
            } 
                        else if (data=="1"){
            document.getElementById("info_id").innerHTML =  "logging in as Admin";
            page();
            }           

        }
        }
        http.send(null); 
             }
    function page(){
        var request = new XMLHttpRequest();
        request.onreadystatechange = function() {
            if (request.readyState === 4) {
            if (request.status === 200) {
                //document.body.className = 'ok';
                //console.log(request.responseText);
            } else {
                //document.body.className = 'error';
            }
            }
        };
        request.open("GET", "index.html" , true);
        request.send(null);

      }
    </script>

函数显示(){
var ID=document.getElementById(“用户ID”).value;
var passwrd=document.getElementById(“password_id”).value;
var login=“/login:”+ID+“-”+passwrd+“-”;
var http=new XMLHttpRequest();
http.open(“GET”,login,true);
http.onreadystatechange=function(){if(http.readyState==4&&http.status==200){
var data=http.responseText;
如果(数据=“0”){
document.getElementById(“info_id”).innerHTML=“密码错误”;
} 
否则如果(数据=“1”){
document.getElementById(“info_id”).innerHTML=“以管理员身份登录”;
第页();
}           
}
}
http.send(空);
}
功能页(){
var request=new XMLHttpRequest();
request.onreadystatechange=函数(){
if(request.readyState==4){
如果(request.status==200){
//document.body.className='ok';
//console.log(request.responseText);
}否则{
//document.body.className='error';
}
}
};
打开(“GET”,“index.html”,true);
请求发送(空);
}
Python baseHTTPServer代码为:

class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_HEAD(s):
    s.send_response(200)
    s.send_header("Content-type", "text/html")
    s.end_headers()


def do_GET(s):
    HTTP_request=s.requestline
    index_1=HTTP_request.index("GET /")
    index_2=HTTP_request.index(" HTTP/1.1")
    file_name=HTTP_request[index_1+5:index_2]
    print 'HTTP_request:',HTTP_request 
    if HTTP_request.find('login')>-1:
        print 'got', file_name  # file name is formatted as "login:anum-1234--"
        ID = file_name[6:file_name.find('-')]
        password = file_name[file_name.find('-')+1:file_name.find('--')]
        if ID == "anum" and password == "1234":
            admin = 1
            print 'admin ENTERED'  # <--working till here
            file1=open('index.html','r')
            file_read=file1.read()
            s.send_response(301)
            s.send_header('Location','http://index.html') # <- is it correct this way ?
            #s.send_header('Location',file_read)  ## <- or this way
            s.end_headers() 
        else:
            admin = 0  
            s.wfile.write("0")
类MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_头:
s、 发送响应(200)
s、 发送标题(“内容类型”、“文本/html”)
s、 end_headers()
def do_获得:
HTTP_request=s.requestline
index_1=HTTP_request.index(“GET/”)
index_2=HTTP_请求.index(“HTTP/1.1”)
文件名=HTTP请求[索引1+5:索引2]
打印“HTTP\u请求:”,HTTP\u请求
如果HTTP_请求.find('login')>-1:
打印'got',文件名#文件名格式为“login:anum-1234--”
ID=文件名[6:文件名.查找('-')]
密码=文件名[文件名.查找('-')+1:文件名.查找('-')]
如果ID==“anum”和密码==“1234”:
管理员=1

打印“管理员输入”#为什么要这样做?为什么不使用一个合适的框架呢?对不起,我对这一切都很陌生。我只是想知道如何重定向到新页面。但这不是你应该做的事情,尤其是如果你是新手。在此处安装并遵循介绍。
class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_HEAD(s):
    s.send_response(200)
    s.send_header("Content-type", "text/html")
    s.end_headers()


def do_GET(s):
    HTTP_request=s.requestline
    index_1=HTTP_request.index("GET /")
    index_2=HTTP_request.index(" HTTP/1.1")
    file_name=HTTP_request[index_1+5:index_2]
    print 'HTTP_request:',HTTP_request 
    if HTTP_request.find('login')>-1:
        print 'got', file_name  # file name is formatted as "login:anum-1234--"
        ID = file_name[6:file_name.find('-')]
        password = file_name[file_name.find('-')+1:file_name.find('--')]
        if ID == "anum" and password == "1234":
            admin = 1
            print 'admin ENTERED'  # <--working till here
            file1=open('index.html','r')
            file_read=file1.read()
            s.send_response(301)
            s.send_header('Location','http://index.html') # <- is it correct this way ?
            #s.send_header('Location',file_read)  ## <- or this way
            s.end_headers() 
        else:
            admin = 0  
            s.wfile.write("0")