ovea / cors Goto Github PK
View Code? Open in Web Editor NEWjQuery CORS Plugin - transparently add CORS support for IE8+ in jQuery using XDomainRequest. Support cookies and headers.
jQuery CORS Plugin - transparently add CORS support for IE8+ in jQuery using XDomainRequest. Support cookies and headers.
When I do a {type: "POST"} request, all kind of headers are appended to the URL as if it were a GET? Is this intentional?
&& !('XMLHttpRequest' in window && 'withCredentials' in new XMLHttpRequest()) // and must not support CORS (IE10+)
works if you replace it with
&& !(window.XMLHttpRequest && 'withCredentials' in new XMLHttpRequest()) // and must not support CORS (IE10+)
I am trying to get CORS in IE to work, but whatever I try, I get a permission denied error. Here is an example:
http://www.stat.ucla.edu/~jeroen/cors/test3.html
Any idea what I am doing wrong? See also this topic: http://stackoverflow.com/questions/11487216/cors-with-jquery-and-xdomainrequest-in-ie8-9
Thanks!!
In IE 9 when I am debugging I can see the response body come back and the ie cors javascript plugin parses the cookies out of the response body. Here is what is in my 'cooks' array on line 516 after parseCookies is made:
[JSESSIONID=1D68129A350A515456A6BB2CA99CB2CF; Path=/my-test-web/,] Object, (Array)
When I get to document.cookie = cooks[i] + ";Domain=" + document.domain; it doesn't add the cookie to the browser. Has anyone else ran into this problem?
Due to the Regex you do it can take very long to execute the parseResponse() method.
I had to comment the line with the Regex to get it done. Maybe there is a possibility to check whether it's really neccessary to do the match or there might be another, better solution.
After reading some MS blogs. MS says the XDR doesn't even support anyhting other than plaintext in the headers for xdr requests. So how are these headers supposed to work?
When the page is local, usage of the adapter is counterproductive.
I suggest the following code to be able to use AJAX also with local pages:
if (
Hey there,
when I request my server in the first place, the response contains a Set-Cookie field which is HttpOnly.
When I request the server the next time, the request doesn't send this cookie at all :-/
Because of that, the server is not allowing any response.
Is that a bug or a missing feature or am I missing something?
Hi there,
it seems that POST-Data is not getting transfered.
The IE Console says i've requestet
set=filter&data%5B%5D=mail&data%5B%5D=sms&data%5B%5D=facebook
in my Zend Framework application the Parameters received are
(
[module] => feed
[controller] => messages
[action] => index
[format] => json
[_xd] => true
)
This is my request
function updateFilters(data) {
$.ajax({
url: '//ajax.localhost/feed/messages',
xhrFields: {
withCredentials: true
},
async: false,
dataType: 'json',
type: 'post',
cache: false,
data: {
set: 'filter',
data: data
}
})
}
// If IE<9, make sure the console.log function at least lets the script run
if (typeof console == "undefined") {
window.console = {
log: function () {}
};
}
_xdr.onload = function () {
// check if we are using a filter which modify the response
var cooks, i, resp = parseResponse(_xdr.responseText || '');
if (debug) {
console.log('[XDR-' + reqId + '] parsing cookies for header ' + resp[2]);
}
cooks = parseCookies(resp[2]);
self.responseText = resp[1] || '';
if (debug) {
console.log('[XDR-' + _id + '] raw data:\n' + _xdr.responseText + '\n parsed response: status=' + resp[0] + ', header=' + resp[2] + ', data=\n' + resp[1]);
}
for (i = 0; i < cooks.length; i++) {
if (debug) {
console.log('[XDR-' + _id + '] installing cookie ' + cooks[i]);
}
document.cookie = cooks[i] + ";Domain=" + document.domain;
}
_done(ReadyState.DONE, resp[0]);
if(typeof(_this.success) === "function"){
// Without this conditional, the program runs normally
_this.success(resp[1]);
}
resp = null;
};
if ($.support.cors){
console.log("CORS supported");
$.ajax({
type: 'POST',
url: 'http://inawire.com/_CORS/testDataJSONP.php',
data: {instructions:"set of instructions"},
dataType: "json",
contentType: 'text/plain',
beforeSend: function(){
console.log("About to send!");
},
complete: function(){
console.log("Done!");
},
xhrFields: {
withCredentials: false
},
counter: {
counter : 0,
num: 0,
init: function(num){
this.num = parseInt(num, 10);
},
add : function(){
this.counter =+ 1;
},
print : function(){
return (this.counter+this.num);
}
},
// success here is expecting a simple integer in a string format
success: function(data) {
console.log("Success!");
console.log(data.returncode);
// When looping through the second time, data.returncode is undefined
this.counter.init(data.returncode);
console.log(this.counter.print());
this.counter.add();
console.log(this.counter.print());
$("#mainContent").html(data.returncode);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log("Failure!");
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
$("#mainContent").html(jqXHR.statusText);
}
});
} else {
$("#mainContent").html('<p>CORS not supported!!</p>');
console.log('javascript alert!');
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.