Skip to content

Instantly share code, notes, and snippets.

@seanhess
Created May 31, 2017 18:12
Show Gist options
  • Save seanhess/876b6b0d39dd3241eddd805aa182be18 to your computer and use it in GitHub Desktop.
Save seanhess/876b6b0d39dd3241eddd805aa182be18 to your computer and use it in GitHub Desktop.
Cors example
<html>
<script>
var xhr = new XMLHttpRequest();
xhr.open("POST", 'http://localhost:8080/applications', true);
//Send the proper header information along with the request
xhr.setRequestHeader("Content-type", "application/json");
xhr.onreadystatechange = function() {//Call a function when the state changes.
console.log("RESPONSE", xhr.status, xhr.readyState)
console.log("RESPONSE", xhr.response)
}
var request = {
application: {
firstName: "bob",
lastName: "wilson",
dateOfBirth: "1982-08-11",
ssn: "111223333",
monthlyIncome: 1234,
email: "[email protected]",
phoneCell: "8013332222",
phoneAlt: "8013332222",
address: { street1: "1234 W Street", street2: "", city: "SLC", state: "UT", zipCode: "84601" },
bank: { routingNumber: "123456789", accountNumber: "123456789" },
paymentSchedule: []
}
}
console.log("SENDING", request)
xhr.send(JSON.stringify(request));
</script>
<body>
Cors test
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment