Created
November 12, 2015 11:47
-
-
Save magicly/348acb0721e6dfd3752c to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head lang="en"> | |
<meta charset="UTF-8"> | |
<title>CORS</title> | |
<style> | |
button { | |
font-size: 5rem; | |
margin-bottom: 1rem; | |
} | |
</style> | |
</head> | |
<body> | |
<div> | |
<h1>Hello CORS</h1> | |
<button id="getCors">GET CORS</button> | |
<button id="getCorsWithCookie">GET CORS With Cookie</button> | |
<button id="postCors">POST CORS</button> | |
<button id="postCorsJson">POST CORS Json</button> | |
</div> | |
<script src="http://libs.baidu.com/jquery/2.1.1/jquery.min.js"></script> | |
<script> | |
var URL = "http://localhost:1337"; | |
jQuery("#getCors").click(function () { | |
$.ajax({ | |
url: URL, | |
method: 'GET', | |
success: function (data) { | |
console.log(data); | |
}, | |
error: function (err) { | |
console.log(err); | |
} | |
}); | |
}); | |
jQuery("#getCorsWithCookie").click(function () { | |
$.ajax({ | |
url: URL, | |
method: 'GET', | |
xhrFields: { | |
withCredentials: true | |
}, | |
success: function (data) { | |
console.log(data); | |
}, | |
error: function (err) { | |
console.log(err); | |
} | |
}); | |
}); | |
jQuery("#postCors").click(function () { | |
$.ajax({ | |
url: URL, | |
method: 'POST', | |
xhrFields: { | |
withCredentials: true | |
}, | |
data: {name: "name", age: 10}, | |
success: function (data) { | |
console.log(data); | |
}, | |
error: function (err) { | |
console.log(err); | |
} | |
}); | |
// jQuery.post("http://localhost:1337", {name: "name", age: 10}, function (data) { | |
// console.log(data); | |
// }); | |
}); | |
jQuery("#postCorsJson").click(function () { | |
$.ajax({ | |
url: URL, | |
method: 'POST', | |
xhrFields: { | |
withCredentials: true | |
}, | |
data: {name: "name", age: 10}, | |
contentType: 'json', | |
success: function (data) { | |
console.log(data); | |
}, | |
error: function (err) { | |
console.log(err); | |
} | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment