Question: Hi I just tried testing if the error function would return an alert but it didn't fire. I altered the url link hoping that it would generate an alert since it won't be able to find or get json data. All I am getting is "Uncaught TypeError: Cannot read property 'length' of undefined jquery-1.9.1.min.js:3"

```
$(document).on('pagebeforeshow', '#blogposts', function () {
    //$.mobile.showPageLoadingMsg();    
    $.ajax({
        url: "http://howtodeployit.com/api/get_recent_po",
        dataType: "json",
        jsonpCallback: 'successCallback',
        async: true,
        beforeSend: function () {
            $.mobile.showPageLoadingMsg(true);
        },
        complete: function () {
            $.mobile.hidePageLoadingMsg();
        },
        success: function (data) {
            $.each(data.posts, function (key, val) {
                console.log(data.posts);
                var result = $('<li/>').append([$("<h3>", {
                    html: val.title
                }), $("<p>", {
                    html: val.excerpt
                })]).wrapInner('<a href="#devotionpost" onclick="showPost(' + val.id + ')"></a>');
                $('#postlist').append(result).trigger('create');
                return (key !== 4);
            });
            $("#postlist").listview();
        },
        error: function (data) {
            alert("Data not found");
        }

    });
});

```

Answer: 
I think the problem is that, when you make the AJAX request your code is executing the `success` callback, not the `error` callback. Thus when you execute:

`$.each(data.posts, function(key, val) {`

The `$.each` function is trying to get the length of `data` which is NULL.

It doesn't look right that you have defined a jsonp callback function and yet your still using the `success` and `error` callbacks. This SO question might help a bit :

[Use of success / jsonpCallback with ajax request](https://stackoverflow.com/questions/7167488/use-of-success-jsonpcallback-with-ajax-request)
I created [a clean Fiddle](http://jsfiddle.net/GcXTA/). Opening the given URL gives a 301 redirect followed by a 200 JSON response. The HTTP status code says that everything is fine, so jQuery doesn't know there was an error.

You mixed up two different concepts here: jQuery's error callback is for network errors and all these things. If you transport error states inside your JSON with HTTP status code 200 you have to deal with it on your own inside the success callback.

Sorry, SO doesn't allow JS-Fiddle links without code:

```
beforeSend: function()  { console.log('beforeSend'); },
complete: function()    { console.log('complete'); },
success:function (data) { console.log('success') },
error: function(data)   { console.log('error') }

```