Setting headers when using jQuery Form Plugin

孤街醉人 提交于 2021-02-07 23:01:20

问题


I'm using JQuery Form Plugin and I'm not sure how to set headers.

I want to be able accomplish something like this:

$.ajax({
                url: "/url",
                data: post,
                type: "POST",
                beforeSend: function(jqXHR) {
                    jqXHR.setRequestHeader("foo", "bar"); 
                },
})

but the beforeSubmit event dosn't pass the jqXHR object for manipulation. Any ideas?


回答1:


The following code works for me.

$('#myForm').ajaxSubmit({
    headers: {
        "foo": "bar"
    }
});



回答2:


As it turns out, the options object you send to the form plugin actually passes the options to the $.ajax method. Therefore you can use the native before send function.



来源:https://stackoverflow.com/questions/7597685/setting-headers-when-using-jquery-form-plugin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!