I am making ajax request using jsonp to the wikimedia api success function works but the error handling is not working.
var wikiRequestTimeout = setTimeout(function() {
self.wikiData = "<p>No Articles Found</p>";
}, 3000);
var wikiUrl = 'https://en.wikipedia.org/w/api.php?action=opensearch&search= ' + this.title + '&format=json&callback=wikiCallback';
$.ajax({
url: wikiUrl,
dataType: "jsonp",
success: function(response) {
var articleList = response[1];
for (var i = 0; i < articleList.length; i++) {
var articleStr = articleList[i];
var url = 'http://en.wikipedia.org/wiki/' + articleStr;
self.wikiData = '<li><a href="' + url + '">' + articleStr + '</a></li>';
};
clearTimeout(wikiRequestTimeout);
}
});
};
To get error handling for failing AJAX requests you need to specify an error callback function. http://api.jquery.com/jquery.ajax/
E.g:
$.ajax({
url: wikiUrl,
dataType: "jsonp",
success: function(response) {
...
},
error: function(jqXHR, textStatus, errorThrown) {
// your error handling goes here
}
});