Handling AJAX Errors With jQuery

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>Handling AJAX Errors With jQuery</title>
	<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
	<script type="text/javascript" src="script.js"></script>
	<script type="text/javascript">
 
		// Initialize document.
		$(
			function(){
				var objAJAX = new AJAX();
 
				// Get reference to the three links.
				var j404 = $( "#error-404" );
				var jNoError = $( "#no-error" );
 
				// Set up 404 link.
				j404
					.attr( "href", "javascript:void(0)" )
					.click(
						function( objEvent ){
							// Make AJAX request.
							objAJAX.GetJSON(
								"does-not-exist.cfm",
								{},
								Do404RequestHandler
								);
 
							// Prevent default.
							objEvent.preventDefault();
							return( false );
						}
						)
				;
 
				// Set up no-error link.
				jNoError
					.attr( "href", "javascript:void(0)" )
					.click(
						function( objEvent ){
							// Make AJAX request.
							objAJAX.GetJSON(
								"NoErrorRequest",
								"200.cfm",
								{},
								NoErrorRequestHandler
								);
 
							// Prevent default.
							objEvent.preventDefault();
							return( false );
						}
						)
				;
			}
			);
 
 
		// I handle the 404 request repsonse.
		function Do404RequestHandler( objResponse ){
			// Check to see if request was successful.
			if (objResponse.SUCCESS){
 
				alert( "Success!" );
 
			} else {
 
				alert( "404 Error!" );
			}
		}
 
 
		// I handle the no-error request repsonse.
		function NoErrorRequestHandler( objResponse ){
			// Check to see if request was successful.
			if (objResponse.SUCCESS){
 
				alert( "Success!" );
 
			} else {
 
				alert( "No-Error Error!" );
			}
		}
 
	</script>
</head>
<body>
 
	<h1>
		Handling AJAX Errors With jQuery
	</h1>
 
	<p>
		<a id="error-404">404 Error</a> &nbsp;|&nbsp;
		<a id="no-error">Success</a>
	</p>
 
</body>
</html>

For Cut-and-Paste