javascript - Headers and Submit Form -


i'm working on front side of jsf (myfaces 2.2.10) project. navigator, need modify header of http request sent on submit event of form.

to more specific, need set accept-language header specific value determined page.

i read cannot modify or add header on http request sent html form. confirm ?

what tried:

  1. trying modify xmlhttprequest.prototype.setrequestheaders, submission of form doesn't use xhr, it's pure html.

  2. adding eventlistener on form, , sending request through xhr modified header:

    document.getelementbyid("form").addeventlistener("submit", function (e) {     e.preventdefault();     var form = document.queryselector('#form');     var req = new xmlhttprequest();     req.onreadystatechange = function () {         if (req.readystate === 4) {             document.head = req.response.head;             document.body = req.response.body;         }     }     req.open(myform.method, myform.action);     req.responsetype = "document";     req.setrequestheader("content-type", "application/x-www-form-urlencoded");     req.setrequestheader("accept-language", localstorage.getitem("language"));     req.send(serialize(form)); //https://github.com/defunctzombie/form-serialize/blob/master/index.js }); 

with solution, i've been facing issues reload page once injected body , header.

what other options have? jsf modification?

thanks,

edit1:

if write

var win = window.open("", '_top'); win.document.write(req.response.head.innerhtml); win.document.write(req.response.body.innerhtml); 

the page loaded , css files well. however, js scripts not loaded, i'm wondering why.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -