JSFiddle - React, Tailwind, and code Playground
by Aravind Baskaran
HTML
<form enctype="multipart/form-data" action="/echo/html" method="post" name="fileinfo" accept-charset="windows-1251">
<label>Label:</label>
<input type="text" name="label" size="12" maxlength="32" value="får løbende" /><br />
<input type="submit" value="Send standart">
</form>
<button onclick="sendForm()">Send ajax!</button>
<button onclick="sendFormEscaped()">Send escaped ajax!</button>
<button onclick="sendFormLikeBrowser()">Send ajax like the browser!</button>
JavaScript
window.sendForm = function() {
var oOutput = document.getElementById("output"),
oData = new FormData(document.forms.namedItem("fileinfo"));
var oReq = new XMLHttpRequest();
oReq.open("POST", "/echo/html", true);
oReq.send(oData);
}
window.sendFormEscaped = function(){
var oOutput = document.getElementById("output"),
oData = new FormData();
oData.append("label", escape(document.forms.namedItem("fileinfo").label.value));
var oReq = new XMLHttpRequest();
oReq.open("POST", "/echo/html", true);
oReq.send(oData);
}
window.sendFormLikeBrowser = function(){
var oOutput = document.getElementById("output"),
oData = new FormData();
oData.append("label", numericEscape(document.forms.namedItem("fileinfo").label.value));
var oReq = new XMLHttpRequest();
oReq.open("POST", "/echo/html", true);
oReq.send(oData);
}
function numericEscape(s){
return s.replace(/[\u00A0-\u2666]/g, function(c) {
return '&#'+c.charCodeAt(0)+';';
});
}