tags:

views:

21

answers:

1

Im trying to load an xml file using the jquery ajax function,it works fine in safari but fails in IE6,is there any reason why this the case?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
    <html xmlns="http://www.w3.org/1999/xhtml"&gt;
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link rel="stylesheet" type="text/css" media="all" href="style.css" />
        <script type="text/javascript" src="jquery.js"></script>
        <title>Reading XML with jQuery</title>
         <script>
            $(document).ready(function(){
                $.ajax({
                    type: "GET",
                    url: "sites.xml",
                    dataType: "xml",
                    success: function(xml) {
                        $(xml).find('site').each(function(){
                            var id = $(this).attr('id');
                            var title = $(this).find('title').text();
                            var url = $(this).find('url').text();
                            $('<div class="items" id="link_'+id+'"></div>').html('<a href="'+url+'">'+title+'</a>').appendTo('#page-wrap');
                            $(this).find('desc').each(function(){
                                var brief = $(this).find('brief').text();
                                var long = $(this).find('long').text();
                                $('<div class="brief"></div>').html(brief).appendTo('#link_'+id);
                                $('<div class="long"></div>').html(long).appendTo('#link_'+id);
                            });
                        });
                    }
                });
            });
         </script>
    </head>
    <body>
        <div id="page-wrap">
            <h1>Reading XML with jQuery</h1>
         </div>
    </body>
    </html>

Thanks

A: 

I have two ideas for you:

  1. I believe some browsers' xml implementations are case sensitive. make sure your $(xml).find('site') if the xml has <Site> or <SITE> it may not work.

  2. if the sites.xml is a local file, you may have issues loading it with ajax. Try putting it on a webserver as manraj82 suggested

Jiaaro
thanks for the answer,its weird but it worked when viewed from a web server in IE... sites.xml is a local file[development machine],dont really understand why IE6 failed,has it got something to do with the mimetype??
manraj82