0

what I want to do is to add the token to request in the submmiting form. How can I achieve this? This is my code,the :action comes from 'vue-bind'.

 <form method="post" enctype="multipart/form-data" :action="mainUrl+'/nameList'">
                    <ol>
                        <li><a href="http://120.55.113.9:8080/prizesearch-main/file/NameList.xls">download the files</a></li>
                        <li><input type="file" @change="jsReadFiles" :files="files" ref="inputfile" name="nameListFile"></li>
                        <li><input type="submit" value="upload the files"></li>
                    </ol>
</form>
edison xue
  • 1,151
  • 2
  • 12
  • 20

1 Answers1

1

You can simply use jQuery's beforeSend callback to add an HTTP header with the authentication information:

beforeSend: function (xhr) {
  xhr.setRequestHeader ("Authorization", token);
},

Refer this for more info.

rnavagamuwa
  • 198
  • 11
  • Acutally, I am not quiet familiar with JQuery. Is there a way to achieve this just in JS? I don't know how to manipulate the request in the form. Do I have to prevent the submit and construct my own request? – edison xue Jun 13 '17 at 10:01
  • 1
    Create a js function and pass relevant arguments when the submit button is pressed. Create the request inside your js function. You can append the request like `req.setRequestHeader('Authorization', token );` – rnavagamuwa Jun 13 '17 at 10:08