zoukankan      html  css  js  c++  java
  • Ajax关于重定向

    AJAX即Asynchronous Javascript And Xml,异步javascript和xml,主要用户在不刷新页面的情况下与服务器数据交互。

    Ajax主要用到的对象为XMLHttpRequest(在IE5、IE6中为ActiveXObject)

    if(window.XMLHttpRequest){

      xmlhttp = new XMLHttpRequest();

    }

    else{

      xmlttp = new ActiveXObject("Microsoft.XMLHTTP");

    }

    xmlhttp.open(method,url,async);

    xmlhttp.setRequestHeader()

      xmlhttp.onreadystatechange = function(){

        if(xmlhttp.readyState ==4&&xmlhttp.status==200){

          xmlhttp.getResponseHeader(string)

          xmlhttp.responseXML

          xmlhttp.responseText

        }

      }

      xmlhttp.send(string);

    ---------------------------------------------------------------------------------------------------------

      &.ajax({

        type:"GET",

        url:"http://",

        success:function(msg){},

        error:function(xmlhttprequest,textstatus,errorThrow){},

        statusCode:{

          404:function(){}

        },

        complete:function(xmlhttprequest,textstatus){}

      });

      正常情况下,ajax向指定url以指定方法发送数据,服务器处理完之后返回状态200,且content-type:text/plain的数据,客户端接收到返回的数据进行处理。如果发送ajax数据时session已过期,服务器要求重定向到登陆页面,此时前台并不能获取到302的状态码,XMLHttpRequest对象会直接向后台发起重定向请求,然后返回状态200,content-type:text/html;msg以及responseText为登陆页面的html。

      在complete中判断如果返回的content-type为text/html则显示该页面

      document.write(xmlhttprequest.responseText);

      document.close();(必须的)

      如果ajax请求是在嵌套页面中发送的,登陆页面要显示在最顶层的页面中,可以在登录页面中调用

      if (top.location != window.location) {
                top.location = window.location;
            }

      防止页面嵌套。

  • 相关阅读:
    JQuery中$.ajax()方法参数详解
    overload和override的区别
    linux 安装jdk和tomcat
    linux链接外网手动设置
    RISC与CISCCPU构架
    32位与64位内存区别
    system 系统调用、gcc编译过程
    c helloworld
    C语言中 有符号数、无符号数、整数溢出 (转)
    samba安装
  • 原文地址:https://www.cnblogs.com/chunchengwuchu/p/4103781.html
Copyright © 2011-2022 走看看