No 'Access-Control-Allow-Origin' header is present on the requested resource error
If you use Google Chrome browser you can hack with an extension.
You can find a Chrome extension that will modify CORS headers on the fly in your application. Obviously, this is Chrome only, but I like that it works with zero changes anywhere at all.
You can use it for debugging your app on a local machine (if everything works in production).
Notice: If URL becomes broken the extension name is Access-Control-Allow-Origin: *. I recommend you to disable this extension when you not working on your stuff, because, for example, youtube does not work with this extension.
I believe this might likely be that Chrome does not support localhost
to go through the Access-Control-Allow-Origin
-- see Chrome issue
To have Chrome send Access-Control-Allow-Origin
in the header, just alias your localhost in your /etc/hosts file to some other domain, like:
127.0.0.1 localhost yourdomain.com
Then if you'd access your script using yourdomain.com
instead of localhost
, the call should succeed.
Try this - set Ajax call by setting up the header as follows:
var uri = "http://localhost:50869/odata/mydatafeeds"
$.ajax({
url: uri,
beforeSend: function (request) {
request.setRequestHeader("Authorization", "Negotiate");
},
async: true,
success: function (data) {
alert(JSON.stringify(data));
},
error: function (xhr, textStatus, errorMessage) {
alert(errorMessage);
}
});
Then run your code by opening Chrome with the following command line:
chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security