Created
May 7, 2013 21:22
-
-
Save booknara/5536243 to your computer and use it in GitHub Desktop.
CORS Test file(GET)
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
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<title>MDN Example – AJAX and forms</title> | |
<script type="text/javascript"> | |
function AJAXGet(oForm) { | |
if (oForm.method.toLowerCase() !== "get") { return; } | |
var query = []; | |
var xhr = new XMLHttpRequest(); | |
for (var nItem = 0; nItem < oForm.elements.length; nItem++) { | |
var field = oForm.elements[nItem]; | |
if (!field.hasAttribute("name") || (/^(?:radio|checkbox)$/.test(field.type) && !field.checked)) { continue; } | |
query.push(escape(field.getAttribute("name")) + "=" + escape(field.value)); | |
} | |
xhr.onload = function() { | |
alert(this.responseText); | |
}; | |
xhr.onerror = function() { | |
alert("An error occurred while submitting the form."); | |
}; | |
xhr.open("get", query.length ? oForm.action + "?" + query.join("&") : oForm.action, true); | |
xhr.send(null); | |
} | |
</script> | |
</head> | |
<body> | |
<!-- Change Request URL in action property--> | |
<form onsubmit="AJAXGet(this); return false;" action="https://www.example.com" method="get"> | |
<p> | |
Param: <input type="text" name="param" /><br /> | |
<p> | |
<input type="submit" value="Submit" /> | |
</p> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment