用原生ajax将信息放到请求头中

export function setHeaderRequest(url, options){
    const setData = {
        "data": JSON.stringify({
            "pageId" : "test data"
        })
    };
    var xhr = $.ajax(url,  {
        data: options.data,
        type: options.method || 'post',
        success: options.success || undefined,
        error: options.error || undefined,
        beforeSend: options.beforeSend || undefined,
        complete: options.complete || undefined,
        headers: setData
    });
    return xhr;
}

 有的时候,一些信息要通过请求头返回给后端,可以用这种方法 

posted @ 2018-06-06 17:52  small_winder  阅读(929)  评论(0编辑  收藏  举报