-1

UPDATE: the script works now (partially), but it fails to load some XML gadget files that have Javascripts in their Content; also, some are loaded fine but anything other then the Content it's still not displayed. I wonder if this can be done only in PHP rather than jquery.

I have the code that I use to load and display XML gadgets (like those from iGoogle). It is now my creation, in fact I don't even remember where I got it from.

Anyway, as you can see, the code reads the Content from an XML file and displays it in the combo1 span. This works as it's supposed to.

The problem is that anything I write, before or after the span, doesn't show. Or it shows for a fraction, but immediately the Content is displayed and everything else is hidden. I would like the "I want this text visible !!!" to be, well, visible. How can I do that? I don't care if it is just text, or maybe jQuery can do another trick to display this, too (I've tried some, didn't work), or maybe "my" code is at fault and needs some changes.

All I know is that I need help.

P.S. if you need to test this use the Google's hello gadget: http://www.google.com/ig/modules/hello.xml - you must save it locally, I think the script doesn't read external files.

OK, for your reference, I have this:

<?PHP
$xml = $_GET['xml'];
echo "<html><head></head><body><script src='http://code.jquery.com/jquery.min.js' type='text/javascript'></script>
        <script type='text/javascript'>
        $(document).ready(function(){
    function loadfail(){
        alert('Error: Failed to read file!');
    }
    function parse(document){
        $(document).find('Module').each(function(){
           $('.combo1').append(
            '' + $(this).find('Content').text() +
            ''
           );
        });
    }
    $.ajax({
        url: '$xml',
        dataType: 'xml',
        success: parse,
        error: loadfail
    });
});
</script><span class='combo1'></span>";
?>Text that I'd like to show</body></html>
  • Can we get a little more info? Possible set up an example at jsfiddle.net? Text doesn't have to be inside elements to be visible. If the element is rendering on the page it should show unless the parent element is being told to hide it. For example, you can write straight text into a tag with no divs and it'll show up. We need to know if the text is being read at all, if the AJAX is not firing properly, etc... – Wesley Aug 09 '12 at 16:51
  • Sure, but it won't help, because the .xml file must be on the same domain as the page (http://jsfiddle.net/G2sZz/). I think it is better if you create a html file on your computer, using this code, and doenload the hello.xml in the same folder, from Google (see above). – Daniel George Aug 09 '12 at 16:55
  • the text "I want this text visible !!!" does show up for a second, but after the script loads the xml file, it is replaced by this (?!) ... over my head. – Daniel George Aug 09 '12 at 16:56
  • I just tested it (with Firefox) and it worked. I just added jQuery and replaced "daily-girls.xml" with "hello.xml" – fehrlich Aug 09 '12 at 17:05
  • Those girls are distracting my jquery – VoronoiPotato Aug 09 '12 at 17:07
  • @XzenTorXz did it show the text after the span, like I want to? – Daniel George Aug 12 '12 at 19:03

1 Answers1

0

OK, I'm answering my own post (LOL), maybe this thread will close like this. The code above, in my first question, finally works. However, it depends on the xml file Content. After I tested it with tens of xml files I conclude that not all of them will allow the other elements to be displayed. With xml files, those who contain javascript in the Content, the script will not allow anything else to show, displaying only the Content of the xml file, and nothing else. I suppose these are the javascript limitations and, for better results, one should use PHP to do what I asked.