Pipes now has Cross-Origin Resource Sharing (CORS) support.

If you use a modern browser (FF3.5+,Chrome 3+,Safari 4+,IE8+) you can now access Pipes data using AJAX from a different domain.

You can use YUI3 IO (use: ‘native’) to make the request for you or you can hand craft your own.

Some sample code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <title>Pipes CORS test</title>
        <script src="https://github.com/douglascrockford/JSON-js/raw/master/json2.js">
        </script>
    </head>
    <body>
        <div id="output">
        </div>
        <script>
            function createCORSRequest(method, url){
                var xhr = new XMLHttpRequest();
                if ("withCredentials" in xhr) {
                    xhr.open(method, url, true);
                } else
                    if (typeof XDomainRequest != "undefined") {
                        xhr = new XDomainRequest();
                        xhr.open(method, url);
                    } else {
                        xhr = null;
                    }
                return xhr;
            }

            var request = createCORSRequest("get", "http://pipes.yahoo.com/pipes/pipe.run?_id=ZKJobpaj3BGZOew9G8evXg&_render=json&ticker=YHOO,GOOG");

            if (request) {
                request.onload = function(){
                    var r = JSON.parse(request.responseText);
                    var holder = "";
                    for (var x = 0, rl = r.value.items.length; x < rl; x++) {
                        holder += r.value.items[x].title + "<br>";
                        holder += r.value.items[x].description;
                        holder += "<hr>";
                    }
                    document.getElementById("output").innerHTML = holder;
                };
                request.send();
            }
        </script>
    </body>
</html>
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>