0

I know this has been asked before, but I can't figure out what's wrong, I'm trying to load in a XML file with a list of shows using jQuery so that the shows can be updated in one file, and upload onto multiple pages. To me it seems like I'm doing everything right, but my knowledge jquery is fragile at best. Most of it is just pieced together from answers to others questions.

my HTML

<aside id="shows"class="aside shadow">
<div class="text" id="table">
<div class="more low"> MORE SHOWS </div>
<div class="less"> LESS SHOWS </div>
</div>
</aside>

my Jquery

function showData() {
$.ajax({
   type: "GET",
   url: "shows.xml",
   dataType: "xml",
   success: function getShows(a) {
    $('#table').append('<h2>SHOWS</h2>'); 
    $('#table').append('<table>'); 

    $(a).find('show').each(function(){
        var $show = $(this);
        var date = $show.find('date').text();
        var place = $show.find('place').text();
        var location = $show.find('location').text();
        var time = $show.find('time').text();

        var html = '<tr><td class="bold">' + date + '</td><td class="hide">' + place + '</td><td>' + location + '</td><td class="bold">' + time + '</td></tr></table>';

        $('<table>').append(html);

    });
    }
 });
}

and XML

<shows>
<show>
    <date>9/8</date>
    <place>Toads Place</place>
    <location>New Haven, CT</location>
    <time>9PM</time>
</show>

</shows>

This does NOTHING and This looks totally right to me, so I'm super confused. Knowing me, I'm missing a semi colon. ><

Thanks!!

Jay
  • 1
  • 1
  • 1
  • And what do you mean by nothing happens? Open up your console and see if it says anything. ctrl+shift+j with chrome, ctrl+f4 with Firefox, alt+f4 with Ie – mowwwalker Oct 02 '11 at 08:28
  • what would I be looking for? Just looking at console there's nothing that involves this script, just some warnings about the jquery library, facebook, and...errors with firebug? – Jay Oct 02 '11 at 08:41

2 Answers2

0

Try to put the exact url...

url: "shows.xml",

...maybe the shows.xml isn't in the same folder than the Jquery ajax function

A.Quiroga
  • 5,704
  • 6
  • 37
  • 58
0

Can you confirm the ajax call works fine and the success method is called.
You can check the ajax call and the response on firebug.
If the xml is returned fine, you may want to try below, modified the success method a little e.g. http://jsfiddle.net/Jayendra/2PFxr/

Try -

$.ajax({
    type: "GET",
    url: "shows.xml",
    dataType: "xml",
    success: function(xml){
        $('#table').append('<h2>SHOWS</h2>'); 
        $('#table').append('<table id="show_table">'); 
        $(xml).find('show').each(function(){
            var $show = $(this);
            var date = $show.find('date').text();
            var place = $show.find('place').text();
            var location = $show.find('location').text();
            var time = $show.find('time').text();
            var html = '<tr><td class="bold">' + date + '</td><td class="hide">' + place + '</td><td>' + location + '</td><td class="bold">' + time + '</td></tr>';
            $('#show_table').append(html);
        });
    }
});
Jayendra
  • 52,349
  • 4
  • 80
  • 90
  • When is the showdata method invoked ? Else you can put the ajax call directly on document ready as is the fiddle example and then debug the ajax calls. – Jayendra Oct 02 '11 at 09:38
  • Thanks SO MUCH!!!!! I figured out how to check the ajax call in Firebug, and it helped me find out that A.Quiroga was right in that shows.xml couldn't be found! And you code is right in that the shouldn't have been there ><. I'm going to be using that .net thing on firebug ALOT from now on, so future thanks. I probably seem super dumb. – Jay Oct 02 '11 at 09:57