zoukankan      html  css  js  c++  java
  • jQuery.ajaxSetup()

    jQuery中AJAX请求的默认设置选项。之后执行的所有AJAX请求,如果对应的选项参数没有设置,将使用更改后的默认设置。

    该函数属于全局jQuery对象。

     /**
       * ajax初始化
       */
    
      jQuery.ajaxSetup({
        type: "post",
        dataType: "json",
        cache: false,
        box_obj: null,
        scroll: null,
        beforeSend: function (request) {
          //需要登录校验,且用户未登录
          if (this.login && !istrsidssdssotoken()) {
            // request.abort();
            // jumpToLoginPage();
          }
          //csrf校验
          if (this.csrf) {
            var crm = Math.random();
            //判断语句,用于本地测试,请勿提交测试或生产
            if (window.location.host.indexOf('localhost') >= 0) {
              crm = '123';
            }
            // var urlDomain = this.url.
            $.cookie('crm', crm, {
              'path': '/',
              'domain': '.xxx.com'
            });
            if (this.url.indexOf('?') >= 0) {
              this.url = this.url + '&cch=' + crm;
            } else {
              this.url = this.url + '?cch=' + crm;
            }
          }
    
          //contentType: "application/json; charset=utf-8",
          if (this.applicationType) {
            request.setRequestHeader("Content-Type", "application/json; charset=utf-8")
          }
        },
        success: function (data) {},
        complete: function (XMLHttpRequest, textStatus) {
          //csrf校验-删除cookie
          if (this.csrf) {
            $.cookie('crm', null, {
              'path': '/',
              'domain': '.XXX.com'
            });;
          }
        },
        error: function (jqXHR, textStatus, errorThrown) {
          if (this.login && jqXHR.status == 401) {
            // jumpToLoginPage();
          }
          if (this.error_cb) {
            this.error_cb(jqXHR, textStatus, errorThrown);
          }
        }
      });
  • 相关阅读:
    数据结构习题
    POJ 2965 The Pilots Brothers' refrigerator
    POJ 1753 Flip Game
    HDU 1172 猜数字
    假币问题
    HDU 1425 sort
    Java基础知识
    P1650 田忌赛马
    SQL注入之Sqli-labs系列第十九关(基于头部的Referer POST报错注入)
    SQL注入之Sqli-labs系列第十八关(基于错误的用户代理,头部POST注入)
  • 原文地址:https://www.cnblogs.com/qiu2841/p/10855752.html
Copyright © 2011-2022 走看看