0

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>');
                        }
                    });
                });
            }
        });
2
  • 1
    the dataType must always be xml, regardless which browser. Commented Jan 26, 2011 at 11:00
  • 1
    @jAndy - I had to add that to get webkit & IE to play ball. Commented Jan 26, 2011 at 11:02

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

2 Comments

Sorry, I don't understand. I already have this code and I'm not generating any XML at all (and this will be hosting on one domain only....).
PREload... preload preload preload

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.