Created
April 29, 2013 05:57
-
-
Save joaoneto/5479938 to your computer and use it in GitHub Desktop.
jQuery ajax with CORS
This file contains hidden or 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> | |
<header> | |
<title>Dev tools</title> | |
</header> | |
<body> | |
<h1>Dev tools</h1> | |
<div data-scope="main"></div> | |
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script> | |
<script type="text/javascript" src="socket.io.min.js"></script> | |
<script type="text/javascript"> | |
(function (window, document, $, io) { | |
'use strict'; | |
$.support.cors = true; | |
var xhrCorsFields = { | |
withCredentials: true | |
}; | |
function corsReq(options, data, type, callback) { | |
var settings = $.extend({}, $.ajaxSettings, { xhrFields: xhrCorsFields }); | |
settings.crossDomain = true; | |
if ('string' === typeof options) settings.url = options; | |
else settings = $.extend(settings, options); | |
if ('string' === typeof data) settings.type = data; | |
else if (data) settings.data = data; | |
if ('function' === typeof type) settings.complete = type; | |
else if (type) settings.type = type; | |
if (callback) settings.complete = callback; | |
console.log(settings); | |
return $.ajax(settings); | |
} | |
// corsReq('http://localhost:3000/v1/sessions', { email: '[email protected]', password: '123' }, 'POST', function (res) { | |
// console.log(res); | |
// }); | |
window.corsReq = corsReq; | |
$(document).ready(function () { | |
}); | |
})(window, document, window.jQuery, window.io); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment