javascriptweb-scrapingyui

Can YUI 3.4.1 Be Used to fetch text from a remote web server?


Within the context of a web application written using the YUI library 3.4.1 it is necessary to load free-form text data from a remote server. I've looked DataSource Get and IO examples in YUI documentation (http://yuilibrary.com/yui/docs/datasource/), both of which appear to require formatted (JSON or XML) data from the remote server.

What is the simple case using YUI code to demonstrate accessing this non-HTML text data?

For discussion purposes the remote data is at http://foo/bar.php


Solution

  • Instead of messing with the DOM, just use o.responseText, as shown in the examples at http://yuilibrary.com/yui/docs/io/. This doesn't require the response to be JSON, XML, or any other specific type of data.

    However, depending upon what you mean as "remote server", please pay particular attention to the note on cross-domain transactions. (Everything here should equally apply to the node-load method as well.)