GithubHelp home page GithubHelp logo

ovea / cors Goto Github PK

View Code? Open in Web Editor NEW
69.0 8.0 21.0 356 KB

jQuery CORS Plugin - transparently add CORS support for IE8+ in jQuery using XDomainRequest. Support cookies and headers.

Shell 0.56% Java 43.92% JavaScript 55.51%

cors's People

Contributors

altus34 avatar mathieucarbou avatar punitrathore avatar sdepold avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cors's Issues

POST adds headers to url?

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?

document.cookie isn't working

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?

parseResponse() takes very long to execute

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.

Headers don't work with ie8+

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?

Adapter should be ignored on local file domain

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 ($.browser.msie &amp;&amp; 'XDomainRequest' in window &amp;&amp; !(ns in $) && document.location.href.strpos("file:///") < 0)

httponly cookies not send

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?

POST-Data not transfered

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
    }
  })
}

Calling callback within onload executes $.ajax.success() twice

// 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!');
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.