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;
            }

      防止页面嵌套。

  • 相关阅读:
    spring04
    kepp running 团队视频分析初步总结
    spring03
    第六周学习进度博客
    spring02
    spring初级java 应用。搭建环境。基本语法
    给定一个整数数组 nums 和一个目标值 target,求nums和为target的两个数的下表
    团队项目-运动App
    第五周学习进度博客
    java编写规范
  • 原文地址:https://www.cnblogs.com/chunchengwuchu/p/4103781.html
Copyright © 2011-2022 走看看