放在请求头中

 $.ajax({
                type: "post",
                url: "http:///test/getInfo",
                headers: {      //请求头
                    Accept: "application/json; charset=utf-8",
                    token: "" + token  //这是获取的token
                },
                data:JSON.stringify(jsonDate),
                contentType: "application/json",  //推荐写这个
                dataType: "json",
                success: function(data){
                	console.log('ok');
                },
                error:function(){
                    console.log('error');
                }
            })

使用beforeSend方法设置请求头

 $.ajax({
                type: "post",
                url: "http://aliyun.seatang:8080/onlinejudge/test/getInfoById",
                beforeSend: function(request) {      //使用beforeSend
                    request.setRequestHeader("token", token);
                     request.setRequestHeader("Content-Type","application/json");
                 },
                data:JSON.stringify(jsonDate),
                dataType: "json",
                success: function(data){
                    console.log('ok');
                },
                error:function(){
                    console.log('error');
                }
            })

更多推荐

ajax中传递token的两种方法