-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Fetch requests using FormData not sending the actual data to the …
…server. Fixes #64 When running the requests using the original fetch implementation, we passed in XhookFormData instead of the native FormData object, causing the request to be sent with [Object object] instead of the real data.
- Loading branch information
Showing
7 changed files
with
3,082 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<h5>Fetch with form data</h5> | ||
|
||
<form> | ||
<input type="text" id="username" name="username"> | ||
<input type="password" id="password" name="password"> | ||
<button id="submit" type="button">submit</button> | ||
</form> | ||
|
||
<pre id="result"></pre> | ||
|
||
<script src="https://cdn.jsdelivr.net/fetch/2.0.1/fetch.min.js"></script> | ||
<script src="../dist/xhook.js"></script> | ||
<script type="text/javascript"> | ||
xhook.after(function (request, response) { | ||
console.log(request, response); | ||
}); | ||
|
||
document.getElementById("submit").addEventListener("click", function () { | ||
var username = document.getElementById("username").value; | ||
var password = document.getElementById("password").value; | ||
const data = new FormData(); | ||
data.append('username', username); | ||
data.append('password', password); | ||
console.log("submitting data,", data); | ||
fetch(`http://echo.jpillora.com/cors-test`, { | ||
method: 'POST', | ||
credentials: 'same-origin', | ||
body: data | ||
}).then((response) => { | ||
response.text().then((text) => { | ||
document.querySelector('#result').innerHTML = text; | ||
}) | ||
}) | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.