0

I need to use jquery to parse a drupal xml export that was created with views datasource module. The format of the xml export is shown below and on the browser, its access by entering, say for example, http://mydomain/test.xml, where test.xml represents the path of the xml export.

 <node> 
     <node> 
         <nothing>
            Lorem ipsum 
        </nothing>
      </node>
<node> 

The jquery to parse xml is shown below. But, it does nothing, which is kind of the main problem.

$(document).ready(function(){ 
    $.ajax({
        type: "GET", 
        url: "http://mydomain/test.xml",
        dataType: "xml", 
        success: function(xml){ 
            $(xml).find('node').each(function(){ 
                var title = $(this).find('nothing').text();  
             $('#output').append($(this).find('nothing').text());           
            });
        }
    });
});

1 Answer 1

1

Make sure that the output destination actually exists, and has an ID of "output". Other than that, I'm not positive what your issue could be, but I would add some debugging statements to make sure that your ajax call is even successful.

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

4 Comments

Maclean, thanks for your reply..I actually downloaded the xml created by the module and then created html file which embedded the above jquery, and it worked. But i am still confused on why it would not work on drupal. Maybe i should point out that, the above jquery code is actually embedded to my drupal site as test.js. i am quite new to drupal but does it mean i have to create a template file or something to actually see the changes because going the mydomain/test.xml as specified earlier shows nothing but the xml
Whatever page you have that document ready code on should be loading the ajax call. Make sure that jQuery is properly installed on the page by adding alert('jQuery'); to that document ready function. If you get the alert, then it would appear jQuery has loaded successfully, and there is in fact another issue.
alert('jQuery') works on every page of the site which proves jquery is properly installed. However, when i navigate to the path where the xml export is created within the site, the alert function does not work, which makes sense, seeing that all that is on the page is an xml document
alert() is a javascript function, only placing it within the $(document).ready(function(){}) will tell us if jQuery is installed. I'm not familiar enough with Drupal to know where you are trying to access your page, but navigating directly to the .xml page will obviously not produce what you are trying to achieve.

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.