Solved

Javascript JQuery Code Error

Posted on 2011-03-14
2
2,199 Views
Last Modified: 2013-11-18
Hi all,

I am trying out some code but I cannot get it to conect to the feed...I just get the error but not sure why or how to fix it.

Anyone got any ideas please?

Code is attached below.

Thanks

<html>
<head>

<script type="text/javascript"
 src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/
jquery.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    $.ajax({
                type: "GET",
                url: "http://feeds.bbci.co.uk/news/rss.xml",
                dataType: "xml",
                success: parseXml,
                error: errorMsg
        });

        function parseXml(xml)
        {
                $('#output').empty();
                $(xml).find("entry").each(function()
                {
                        var title = $(this).find('title').text();
                        var pubDate = $(this).find('link').text();
                        var summary = $(this).find('description').text();
                        var thumb = $(this).find('[nodeName=media:thumbnail]').attr('url');
                        var listItem = $('<li><img src=' + thumb + ' /><br/>' + title +
pubDate + '<br/>' + summary + '</li>');
                        $("#output").append(listItem);
                });
        }

        function errorMsg() {
                $("#output").append("error getting xml feed");
        }

  }); <!-- end jq ready -->
</script>

</head>
<body>
<h2>xml test</h2>
<div style="border:1px solid #555">
<div id="foo" style="background-color: #ccc"></div>
        <ul id="output">loading ...</ul>
</div>
</body>
</html>

Open in new window

0
Comment
Question by:error77
  • 2
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 35134042
You're not allowed to do a cross domain ajax call:
you page hosting by www.apple.com can't get data on a page at www.microsoft.com

more info and workaround here for example :
http://jimbojw.com/wiki/index.php?title=Introduction_to_Cross-Domain_Ajax
http://en.wikipedia.org/wiki/Same_origin_policy
http://usejquery.com/posts/9/the-jquery-cross-domain-ajax-guide
http://jquery-howto.blogspot.com/2009/04/cross-domain-ajax-querying-with-jquery.html

Just google for : ajax call cross domain


note cross protocol are not allowed to :
https://www.apple.com can't get a page on http://www.apple.com
0
 
LVL 82

Expert Comment

by:leakim971
ID: 35134270
you page hosting by -> your page hosted by

Thanks for the points! Have a nice week!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now