[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2009-12-27
2
Medium Priority
?
257 Views
Last Modified: 2012-08-13
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

0
Comment
Question by:waffe
2 Comments
 
LVL 11

Accepted Solution

by:
asafadis earned 800 total points
ID: 26126859
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
 

Author Comment

by:waffe
ID: 26129119
ok, no time to figure that out - but thanks for the info.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month18 days, 14 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question