Solved

Javascript JQuery Code Error

Posted on 2011-03-14
2
2,298 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Refresh div via ajax without lost ccs <li> styles 8 31
age from date of birth 4 41
Converting dates in JavaScript 2 32
PHP AJAX Wordpress 9 19
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

786 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