I want to ask is it possible to specify headers before calling $(myForm).submit();
I know you can specify in AJAX post request but is it possible before this si
Yes you can. Requires some native JavaScript
drudgery, this is how I did it:
Custom Header Injection 1
Added a function submitFormAndHeader
which creates an XMLHttpRequest object that adds the required headers and submits a HTML
DOM
form via HTTP POST
.
Alternatively, you can use Jquery submit handler and invoke the submitFormAndHeader()
function created above:
$( "#custom_form" ).on( "submit", function( event ) {
event.preventDefault();
submitFormAndHeader();
});