Nathan
Nathan

Reputation: 1540

Using JS to submit a form with Custom HTTP Headers?

I need to submit a form and include some custom http headers with the request (the API requires them).

Something like jQuery.ajax() works great (https://api.jquery.com/jQuery.ajax/), I can use the beforeSend arg to compose some headers.

However I need this for a synchronous request, to direct the browser to the destination of the form. So one of the following two would work, but I'm not sure if a solution exists.

  1. Have JS create and submit a form. How do I include custom http headers in a form?

  2. Find an equivalent function to jQuery.ajax(), that will submit a synchronous request.

Upvotes: 1

Views: 317

Answers (1)

Badri Narayan Manicka
Badri Narayan Manicka

Reputation: 113

jQuery.ajax has a property async which can be set to true or false.

async false would make it a synchronous request.

Upvotes: 1

Related Questions