Barrie Reader
Barrie Reader

Reputation: 10713

Preloading the XML via jQuery or Javascript

Hey guys, how can I preload an external XML file in Javascript/jQuery?

This is my XML loader:

jQuery.ajax({
            type: "GET",
            url: dictionaryList,
            dataType: ($.browser.msie) ? "text/xml" : "xml",
            success: function(xml) {
                var xml2 = load_xml(xml);
                var i=0;
                $(xml2).find('wordle').each(function(){
                    $(xml2).find('w').each(function(){
                        var tmpHold = $(this).text();
                        if (tmpHold.substring(0, 1) == letter) {
                            if ($(this).attr('p') == 1) {
                                wordColor = 'color: #693030';
                            } else {
                                wordColor = 'color: #5a5a5a';
                            }
                            $('#wordList').append('<li class="w" style="'+wordColor+';">'+$(this).text()+'</li>');
                        }
                    });
                });
            }
        });

Upvotes: 0

Views: 1221

Answers (2)

dan_nl
dan_nl

Reputation: 4446

one possibility, and it sounds like this is what you want, would be to send the response document, (xml) above, to a variable that could be processed on-demand at a later time based on some event.

the stored xml document, and the xml processing function, would live in an object, and the xml processing function would be called based on an event trigger rather than the ajax success event. if this doesn't make sense let me know and i can provide some sample code ...

also, i'd recommend adding an error: function to the ajax call if you don't already have one in place.

Upvotes: 1

sultan
sultan

Reputation: 6058

I think it's good to keep backend xml generator/retriever script in case if you want to get xml from a different domain.


jQuery.ajax({
    type: "GET",
    url: XML_GENERATE_BACKEND_URL, // data.xml, /generate/xml  etc.
..
..
..

Sultan

Upvotes: 0

Related Questions