Ashley Truax
Ashley Truax

Reputation: 1

referenceerror $ is not defined ajax for getting xml

I am using jQuery in my head tag for my offical website. It doesn't work and comes up with the referenceerror $ is not defined $.ajax error. I tried these solutions(down below), but it doesn't solve my problem. The first one di

Solutions Tried:

1.Query needs to be the first script you import. The first script on your page

<script type="text/javascript" src="/test/wp-content/themes/child/script/jquery.jcarousel.min.js"></script>

2.ReferenceError: ajaxfunction is not defined I am calling my function as the first function to be called.

Here is my code:

<script type="text/javascript">
XMLLIST = {
      xml: 'slideshow.xml?' + Math.random(0,1),
      display: '10',
      random: false,
      appentTo: '#slideshow',

      int: function () {
                $.ajax({
                        type:"GET",
                        url:"slideshow.xml",
                             dataType:"xml",
                             sucess: XMLLIST.parseXML,
                }); 
      },

      parseXML: function (xml) {
                var data=$('slideInfo', xml).get();
                var list = data;
                var i = 1;
                          $(list).each(function() {
                          XMLLIST.insertHTML($(this));
                          if( i == XMLLIST.display) return false;
                          i++;
                          });
     },


insertHTML: function (slide) {
            var title = slide.find('title').text();
            var image = slide.find('image').text();
            var alternate = slide.find('alt').text();
            var disclaimer = slide.find('disclaimer').text();
            var diet = slide.find('diet').text();
            var sciencename = slide.find('sciencename').text();
            var facts = slide.find('facts').text();
            var rangehabitat = slide.find('rangehabitat').text();
            var html;

            html = '<div class="slideInfo">';
            html += '<img scr="' + image + '" alt="' + alternate + '"id ="slideImage" />';
            html += '<p id="altTag>"' + alternate + '"</p>"';
            html += '<p id="Animaldisclaimer">"' + disclaimer + '"</p>';
            html += '<p id="scienceName">"' + sciencename + '"</p>'; 
            html += '<p id="RH">"' + rangehabitat + '"</p>';
            html += '<p id="animalFacts">"' + facts + '"</p>';

            $(html).appendTo(XMLLIST.appentTo);
},
}

XMLLIST.int();

Upvotes: 0

Views: 3195

Answers (1)

Michael Geary
Michael Geary

Reputation: 28880

$ is undefined because you're not loading jQuery. You're loading a jQuery plugin, but not jQuery itself. Loading jQuery should get you a little farther, e.g.:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

That goes before any <script> tags that load your plugins or other jQuery scripts.

At least that's all I can guess from the code you posted. If you post a link to a complete test page it would be possible to give more specific advice.

Upvotes: 2

Related Questions