I'm building a page that uses the Slideshare API to pull a limited set of presentations from a specific Slideshare user and output a series of iframes with those presentations embedded.
For the most part the page is working as intended, however one of the presentations that the API is calling was recently deleted, and therefore when the page loads that iframe the browser returns a 410. Unfortunately there is no object in the XML returned by Slideshare that can be used to determine if that particular presentation has been deleted.
Therefore I would like to check for the 410 error prior to adding that particular iframe to the page. What's making this difficult for me is that the error doesn't appear when making the API call, but rather when the embedded iframe loads, so I don't know where or how to make the appropriate check.
Here's the relevant code:
$.ajax({
url: slideShareURL,
dataType: 'XML',
success: function(data) {
var allSlides = x2js.xml2json(data);
allSlides = allSlides.User.Slideshow;
for (i = 0; i < allSlides.length; i++) {
document.getElementById('slides').innerHTML += allSlides[i].Embed;
}
}
});
Notes:
- slideShareURL is defined earlier in the code using the API
- I'm using xml2json.js to convert the XML received from the API to a json object
- allSlides is an array of presentations each containing a set of objects such as slide title, id, download URL, etc
- Embed is the object that contains the full iframe embed code
EDIT: Answer provided by Christophe below was almost perfect, but I had to add a closure to make the second ajax call work within the for loop.