the-petrolhead
the-petrolhead

Reputation: 617

What is the YUI equivalent of JQuery .load()?

I need to use the YUI equivalent for the jQuery .load() function in order to load external HTML template. jQuery code I'm using right now is -

$('#templates').load('file1.html');

How can I achieve the same output using YUI?

Upvotes: 3

Views: 756

Answers (3)

the-petrolhead
the-petrolhead

Reputation: 617

Finally devised a solution for loading the HTML. I have handled the cases for IE and NON-IE browsers. Goes like this -

function fName() {

    if(navigator.appName == "Microsoft Internet Explorer") {        
    var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    xmlHttp.open( "GET", "templates.html", true );

    xmlHttp.onreadystatechange = function() {
        if( xmlHttp.readyState == 4 && ( xmlHttp.status == 0 || xmlHttp.status == 200 ) )
        {                
            document.getElementById( "div_id_here" ).innerHTML = '"' + xmlHttp.responseText + '"';
        }
    };
    xmlHttp.send();
}

else {
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open("GET", "templates.html", true);
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4 && (xmlHttp.status == 0 || xmlHttp.status == 200))
        {
            document.getElementById("div_id_here").innerHTML = xmlHttp.responseText;
        }
    };
    xmlHttp.send();
  }
}

Upvotes: 0

juandopazo
juandopazo

Reputation: 6329

It requires a specific submodule node-load, but it's the same notation.

YUI().use('node', 'node-load', function (Y) {
  Y.one('#templates').load('file1.html');
});

There's a nice list of all methods in jQuery and YUI in: http://www.jsrosettastone.com/

Upvotes: 7

bPratik
bPratik

Reputation: 7019

Not an exact replacement for $.load(...) but might get you started in the right direction:

The only way to load cross-domain HTML files would be to use a cross-domain XMLHttpRequest or Flash. Both of these are supported by the IO module in YUI 3, but are not supported in YUI 2.
Source: http://yuilibrary.com/forum/viewtopic.php?p=25704&sid=33da592b2224850ea738e6947d8dc280#p25704

Upvotes: 0

Related Questions