| <!DOCTYPE html> |
| <!-- This page has a form that submits to the "target" param of the search part |
| of this page's URL. For example if this page's URL is |
| "form.html?target=//example.com/upload", the form submits to |
| //example.com/upload. |
| --> |
| <meta charset="utf-8"> |
| <head> |
| <title>form</title> |
| </head> |
| <form id="form" method="POST" enctype="multipart/form-data"> |
| <input id="text1" type="text" name="text1" value="textValue1"> |
| <input id="text2" type="text" name="text2" value="textValue2"> |
| <input id="file" type="file" name="file"> |
| </form> |
| <script> |
| // Submits using XHR. Used for the subresource test. |
| async function submitXhr(formData) { |
| const xhr = new XMLHttpRequest(); |
| const loaded = new Promise(resolve => { |
| xhr.onload = resolve; |
| }); |
| const loadEnded = new Promise(resolve => { |
| xhr.onloadend = resolve; |
| }); |
| |
| xhr.open("post", form.action); |
| xhr.send(formData); |
| await loaded; |
| await loadEnded; |
| return xhr.responseText; |
| } |
| async function submitFormDataViaXhr() { |
| return submitXhr(new FormData(form)); |
| } |
| async function submitFormDataWithBlobViaXhr(name, content) { |
| const formData = new FormData(form); |
| formData.append(name, new Blob([content])); |
| return submitXhr(formData); |
| } |
| |
| const fileInput = document.querySelector('#file'); |
| const form = document.querySelector('#form'); |
| |
| // Set the form to submit to the |target| param. |
| const documentUrl = new URL(window.location); |
| form.action = documentUrl.searchParams.get('target'); |
| </script> |