Code Monkey home page Code Monkey logo

crossdomain-requests-js's Introduction

About

A small/light script for doing cross-domain, cross-browser ajax requests.

It provides 2 utility methods:

  • crossdomain.ajax(options)
  • crossdomain.async_load_javascript(path, on_load_callback)

ajax() does cross-domain requests. If it cannot use HTTP Access Control (CORS) available in modern browsers, then it falls back to flensed.flXHR, a Flash-based plugin which provides an alternative implementation for XmlHttpRequest.

But flXHR is heavy and doesn't work on mobile-phones well, so if the browser supports CORS, then it prefers doing that.

async_load_javascript() is used internally for asynchronously loading flXHR, only in case it is needed. It loads a Javascript file, and when done it executes the provided callback. Multiple callbacks provided (by multiple calls done at the same time) are stacked.

Further Action

See:

If it doesn't work for you, please open a bug-ticket (with details) and I'll love to fix it for you.

crossdomain-requests-js's People

Contributors

alexandru 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

Watchers

 avatar  avatar  avatar

crossdomain-requests-js's Issues

Parameters/Attributes are not passed through.

I was able to make cross domain requests with this script using both GET and POST, but in both methods that data I passed in by doing data: 'some=json&c=somedata&callback=somecallback' where not getting through to request object on server side.

This is my call;

var jquery_path = "http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js";

uri = readabilityServiceURI;

  // loading jQuery asynchronously
  crossdomain.async_load_javascript(jquery_path, function () {
    $(function () {
      // doing get request
      crossdomain.ajax({
        type: "POST",
        url: uri,
        data: 'some=json&c=somedata&callback=somecallback',
        success: function (data) {
            renderingFunction(data);
        },
        error : function(jqXHR, textStatus, errorThrown) {
            renderingFunction(errorData);
        }
      });
    });
  });

Allow withCredentials be configured

Not all servers want to allow passing credentials, maybe this can be configured and not hard coded?

        try {
            xhr.withCredentials = true;
        } catch (e) {}; 

POST in Chrome does not work

Not sure what's the deal, but as title suggests, POST request does not work in Google Chrome. Running exactly the same code in FireFox works fine.

Network tab of the Chrome Dev Tools shows OPTIONS call with status Failed.
Console shows errors:

On the server app I have a break point on Application_BeginRequest. On the Get method it gets hit every time. However, on the POST it never gets hit. I have an impression that Chrome "kills" request and it never reaches server app.

Just to make sure the headers are not the issue, all the following headers a slapped on any response from the server:

Response.AddHeader("Access-Control-Allow-Origin", "*");
Response.AddHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
Response.AddHeader("Access-Control-Allow-Credentials", "true");
Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control");
Response.AddHeader("Access-Control-Request-Method", "*");
Response.AddHeader("Access-Control-Request-Headers", "*");

Chrome Version 28.0.1500.71 m

Could you please confirm that it indeed behaves this way on Chrome?

HELP Wanted - test in various browsers

Hi,

I've got 2 reports saying that this doesn't work in IExplorer 8 / IExplorer 9.
I did test it on both when I developed this, but I want to make sure that it does work.

Please help me out and test in any browser, especially in IExplorer (since right now I don't have access to one).

Thanks,

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.