前台代码:
<script language="javascript" type="text/javascript">
var typename=null;
function CheckUser(userName,password,type) {
var xmlHttp;
if(window.XMLHttpRequest)
xmlHttp = new XMLHttpRequest();
else
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("POST", "AjaxCheckLogin.aspx", false);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.send("userName=" + userName + "&password=" + password +"&type=" +type);

window.alert(xmlHttp.responseText);
}
我在AjaxCheckLogin.aspx页面后台使用Response.Redirect("index.aspx")跳转页面,为什么无法跳转呢?.net直接把index的html代码用对话框给打出来了!?
大家给点意见啊~~方法可行~马上结贴!!在线等!!!

解决方案 »

  1.   

    当然不能跳转.
    xmlHttp只能得到html内容.
    它与当前浏览器窗口并没有关系.
    在AjaxCheckLogin.aspx中如果检测到没有登录就写个标记,如Response.Write("-1");
    Response.End();前台判断if(xmlHttp.responseText == "-1")
    {
     window.location.href= "index.aspx";
    }
      

  2.   

    cpp2017(慕白兄)
    if(xmlHttp.responseText == "-1")
    {
     window.location.href= "index.aspx";
    }也和我前台代码写一起吗?还是另外写段方法?
      

  3.   

    <script language="javascript" type="text/javascript">
    var typename=null;
    function CheckUser(userName,password,type) {
    var xmlHttp;
    if(window.XMLHttpRequest)
    xmlHttp = new XMLHttpRequest();
    else
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    xmlHttp.open("POST", "AjaxCheckLogin.aspx", false);
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send("userName=" + userName + "&password=" + password +"&type=" +type);
    if(xmlHttp.responseText == "-1")
    {
     window.location.href= "index.aspx";
    }
    else
    window.alert(xmlHttp.responseText);
    }
    是这样吧?