Search code examples
ajaxjsonauthenticationyuidatasource

YUI 3: Setting request headers with DataSource.IO


I need to retrieve a JSON resource which requires HTTP Basic authentication. Therefore, I need to set a request header for a DataSource.IO object.

I see that the IO utility itself supports a header key in its configuration object. However, since I'm new to YUI, I can't figure out how to set this configuration value through the mediation of DataSource.

To be clear, I don't need help constructing a correct Authorization header, just getting YUI to send the headers I construct. Thanks much.


Solution

  • You can set IO config values via DataSource.IO's ioConfig config object:

    var ds = new Y.DataSource.IO({
        source: "script.php",
        ioConfig: {
            method: "POST",
            data: "foo=bar",
            timeout: 1000
        }
    });