try catch not working with $().load();

Hi,

I am using a simple try catch in JavaScript but the catch is never working even if the .load is pointed to a file that is not there. In the code below the second alert never happens even if I point the first .load() to nothing.
<script>
setInterval(function() {
    try{
		$("#slogan_rotate_txt").load("ans.php","");
		alert ("try1");
	} catch(err) {
		$("#slogan_rotate_txt").load("../mod/my1_theme/views/default/my1_pages/slogans.php","");
		alert ("try2");
	} 
}, 5000);
</script>

Open in new window

waffeAsked:
Who is Participating?
 
asafadisConnect With a Mentor Commented:
It doesn't work because jQuery doesn't throw exceptions.  In other words, there's nothing to "catch".
You're best bet would be to use $.ajax() instead of $.load(), and put in your "failure scenario" in the "error" option.
0
 
waffeAuthor Commented:
ok, no time to figure that out - but thanks for the info.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.