jQuery XML解析器

I would like to have a html5 video player (basic tag), and call an external xml file in orderto load and play an ad before the main video.

This is currently working but I would like to have the cleanest and most multiplatform as possible:

function callAd() {
$.ajax({
    type: "GET",    
    url: myexternal_file,
    success: function(xml){
        $(xml).find('MediaFile[type="video/mp4"]').each(function(){
            var preroll = $(this)['context']['textContent'];
            var video = document.getElementById("video1");  
            video.src = preroll;
            video.load();
        });
    }
});
}

And as soon as the page loads, call the callAd function with my external xml. How should I proceed whenever the external url isn't acessible?

Thanks

EDIT: Sorry, the question isn't clear. I would like to know how to correctly parse a XML using javascript/jquery and how should I correctly listen for events coming from this function.

You should use the error function when the URL in not available. If you want to use the resulted data you have to parse it. jQuery.ajax will do this automatically for you if you specify the dataType.

If the resulted data is not valid XML it will throw and error and script execution might end.

var retry = true;
$.ajax({
    type: "GET",    
    url: myexternal_file,
    dataType: 'xml', // use dataType to parse the result as appropriate 
    success: function(xml){
        $(xml).find('MediaFile[type="video/mp4"]').each(function(){
            var preroll = $(this)['context']['textContent'];
            var video = document.getElementById("video1");  
            video.src = preroll;
            video.load();
        });
    },
    error: function(jqXHR, textStatus, errorThrown){
        console.log("Whoops, couldn't load ads: " + textStatus + ' ' + errorThrown);
        // wanna try again? uncomment below
        // if(retry) { callAd(); retry = false; }
    }
});