简体   繁体   中英

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.

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

async false would make it a synchronous request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM