Setting headers when using jQuery Form Plugin

Fatmuemoo picture Fatmuemoo · Sep 29, 2011 · Viewed 7.9k times · Source

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?

Answer

caoxudong picture caoxudong · Aug 12, 2015

The following code works for me.

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