zoukankan      html  css  js  c++  java
  • ajax如何增加请求头

    代码如下(主要关键就是headers,大家可以根据需要来增加请求头):

         $.ajax({
              type: "POST",
              timeout: 10000, // 超时时间 10 秒
              headers: {
               'token': "U2PGBjguSuJg",
               'version': "1.0",
                'from': "test",
              },
          url: "http://www.yctech.com/api/login",
          data:{"username":username,"password":password},
              dataType: "json",
              success: function(data) {
    
            if(data.code=="111111"){
                layui.use('layer', function(){
                              var layer = layui.layer;
    
                              layer.msg(data.msg,{icon:1});
                 });
    
            }else if(data.code=="000000"){
    
                layui.use('layer', function(){
                              var layer = layui.layer;
    
                              layer.msg(data.msg,{icon:1});
                        });
                        setTimeout(() => {
    
                            closeLayui();
                }, 700);
    
            $("#login").hide();
    
            $("#exit").show();
    
            $("#user").html(data.data.nickName);
    
            }
    
              },
              error: function(XMLHttpRequest, textStatus, errorThrown) {
                console.log(XMLHttpRequest.status);
                        console.log(XMLHttpRequest.readyState);
                        console.log(textStatus);
              },
              complete: function(XMLHttpRequest, status) { //请求完成后最终执行参数 
              }
          })
           }
  • 相关阅读:
    koa2环境搭建
    单例模式
    nodejs fs path
    path node
    webpack code splitting
    babel 插件编写
    C#验证码类
    C#身份证识别相关技术
    C# Socket服务端与客户端通信(包含大文件的断点传输)
    动态抓取网页信息
  • 原文地址:https://www.cnblogs.com/youcong/p/10390840.html
Copyright © 2011-2022 走看看