javascript - catching a 500 response when setting the src of an iframe -


i'm doing similar code:

$('#myiframe').attr('src', 'dosomethingthatreturnsadocument.aspx'); 

the page gets called returns document, whether word doc, pdf etc , prompts user open/save , working fine.

the problem have if goes wrong @ server side 500 response returned. don't seem have way of catching error.

i've tried try catch around line. .error function of iframe doesn't seem catch it.

does know of way allow me catch 500 can act accordingly ui?

you should first check response , set in iframe. can try this:

var loading_url = "/dosomethingthatreturnsadocument.aspx" $.ajax({ url: loading_url, type: 'get', complete: function(e, xhr, settings){      if(e.status === 200){           $('#myiframe').attr('src', 'dosomethingthatreturnsadocument.aspx');      }else if(e.status===500){       //      }   } }); 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -