Problem with Jquery - Please help!!

F

fallenangel

Hi

I am using jquery to add an rss feed via yahoo pipes to my page. This
is all working fine as long as the url of the feed can be reached.

However, I need to now add some code which will detect if the url can
be reached and should this not be possible I need to write an error
message. I took a looksee at the documentation on jQuery and noticed
there is an error function which can be attached to the callback in
the url:

$("#").ajaxError(function(request, settings){
$(this).append("<p>Error requesting page " + settings.url + "</
p>");
});

The thing is I do not know enough about jQuery or Javascript to know
where this needs to sit in my code, if I need to define what ajaxError
is before using it and also if I can use it with the way I have done
the code. I also found this:

$.ajax({
type: "post",
url: "http://myServer/cgi-bin/broker" ,
dataType: "text",
data: {
'_service' : 'myService',
'_program' : 'myProgram',
'start' : start,
'end' : end
},
beforeSend: function() {
$("#loading").removeClass("hide");
},
timeout: 5000,
error: function(request,error) {
$("#loading").addClass("hide");
if (error = "timeout") {
$("#error").append("The request timed out, please resubmit");
}
else {
$("#error").append("ERROR: " + error);
}
},
success: function(request) {
$("#loading").addClass("hide");
var t = eval( "(" + request + ")" ) ;
} // End success
}); // End ajax method

which I think is great because it does what I want - with three
different cases for error success and timeout error.
Again I do not know how to implement this though :(

My code is as follows (the url is a dummy one)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Simple Jquery RSS Widget</title>
<script type="text/javascript" src="jquery-1.2.3.pack.js"></script>
<script type="text/javascript">

$('#rssdata').ready(function()
{
var pipe_url = 'http://pipes.yahoo.com/pipes/pipe.run?
_id=test&_render=json&_callback=?';
$.getJSON(pipe_url,function(data)
{
$(data.value.items).each(function(i,item)
{
var item_html = '<li><a href="'+item.link+'">'+item.title+'</
a><p>'+item.description+'</p></li>';

$('#rssdata ul.rss-items').append(item_html);
if ( i == 0 ) return false;

});
$('#rssdata ul.rss-items').fadeIn();
});

});

</script>
</head>
<body>
<div id="rssdata">
<ul class="rss-items">
</ul>
</div>
<link rel="alternate" type="application/rss+xml" href="http://
blog.test.com/feeds/" title="test blog">
<noscript>
<p><a class="bloglink" href="http://blog.test.com/feeds/" title="Click
here for test blog">Click here for test blog</a></p>
<img src="noscript.jpg" width="300" height="140" alt="" border="0" />
<p>
You need to have Javascript enabled to read our blog!
</p>
</noscript>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top