jquery传递http头部
        $.ajax({
            type:'get',
            url: "../../interface/branch/",
            dataType:'json', 
            beforeSend: function(request) {
                request.setRequestHeader("X-Token", 'tokenxxxs5as5as5');// php端获取的时候HTTP_X_TOKEN 全部是大写,换成下划线
            },
            success:function(response){
                console.log(response);
                var data=response.data;
              //      console.log(data);
                $('#branch').empty();
                var t;
               t='<option value="%" >[ 全部门店 ]</option>';
                $('#branch').append(t+data);
                form.render('select');
            }
        })
$hh=$_SERVER['HTTP_X_TOKEN'];  //HTTP_X_TOKEN 全部是大写,换成下划线
jquery post
$.ajax(url, {
    type: 'post',
    data: {}, 
    headers: { myheader: 'my-header-value' },
    success: function(){}
});
$.ajax({
  type: 'POST',
  url: './interface.php?action=1',
  dataType: "json", //表示返回值类型,不必须
  data: {fixed_no:fixed_no},
  success: function (result) {
                    alert(result.data);
                    $("#fixed_no").html(fixed_no);
                },
   error: function (data){
                    alert("网络错误!"+data);
                    console.log(data);
                }


});
$.ajax({
  url:APP + '/Reg/ajax_username'
  type:'post',
  dataType:'json',
  timeout:10000,
  data:{username:username},
  success:function(){ console.log('success');},
  error:function(jqxhr,textStatus,errorThrow){console.log(errorThrow);},
  statusCode:{
   404:function(){console.log('not found');},
   500:function(){console.log('error by server');},
}
});
$.ajax({
  url:'http://www.test.com/equipment/index.php',//远程地址
  type:'post',
  datatype:'json',
  timeout:5000,
  data:{key:str},
  success:function(data1){
    var  obj1 = jQuery.parseJSON(data1); 
    //alert('success');
     localStorage.setItem("User-Token",obj1["User-Token"]); //存入 参数
    localStorage.setItem("vuex",data1); //存入 参数
    alert('登陆成功跳转首页');
    window.location.href='http://www.text.com/cms/';
  },
  error:function(XmlHttpRequest,textStatus, errorThrown)
  {
  alert("操作失败"+XmlHttpRequest.responseText);
  //跳转登陆地址
 // window.location.href='http://www.test.com/login';
  }
});
$.post("../dingding/workback/get_call_back.php", { name: "John", time: "2pm" },
   function(data){
       data = eval('('+data+')'); //使用eval函数
     //alert("Data Loaded: " + data);
   //  layui-callbackfailed
    data.num>0? $('#layui-callbackfailed').html('<span class="layui-badge">'+data.num+'</span>'):'';
   });
//请求 test.php 页面,并一起发送一些额外的数据(同时仍然忽略返回值):
$.post("test.php", { name: "John", time: "2pm" } );
//使用 ajax 请求发送表单数据:
$.post("test.php", $("#testform").serialize());
//输出来自请求页面 test.php 的结果(HTML 或 XML,取决于所返回的内容):
$.post("test.php", function(data){
   alert("Data Loaded: " + data);
 });
//向页面 test.php 发送数据,并输出结果(HTML 或 XML,取决于所返回的内容):
$.post("test.php", { name: "John", time: "2pm" },
   function(data){
     alert("Data Loaded: " + data);
   });
//获得 test.php 页面返回的 json 格式的内容:
$.post("test.php", { "func": "getNameAndTime" },
   function(data){
     alert(data.name); // John
     console.log(data.time); //  2pm
   }, "json");
最后编辑: admin  文档更新时间: 2021-03-16 21:50   作者:admin