Quantcast
Channel: Why do I keep getting an "undefined" error with this JSONP feed? - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Why do I keep getting an "undefined" error with this JSONP feed?

$
0
0

I am using the following code to retrieve data in JSONP format. I need to use it so if no data is returned, I can flag the error. I was using jQuery's ajax(), but it always returns 404 pages as being successful, so I need to use the jquery-jsonp jQuery plug-in on Google Code for error handling.

I borrowed the code from the example on jQuery ajax (jsonp) ignores a timeout and doesn't fire the error event, but I cannot seem to get it to work with my JSON, which is being sent as the MIME type "application/json" from the other server.

$(function(){    var jsonFeed = "http://othersite.com/feed.json";    $.jsonp({        url: jsonFeed,        dataType: "jsonp",        timeout: 5000,        success: function(data, status){            $.each(data.items, function(i,item){                console.log("Title: "+ item.title);                if (i == 9) return false;            });        },        error: function(XHR, textStatus, errorThrown){            console.log("Error Status: "+ textStatus);            console.log("Error Thrown: "+ errorThrown);        }    });});

Here is an example of my JSON:

[ { "title" : "My Title" } ]

Can anyone spot the problem?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images