Skip to content

Instantly share code, notes, and snippets.

@bennadel
Created March 25, 2014 01:05
Catching Timeout Errors With jQuery Powered AJAX
<!--- Param the number of milliseconds to pause. --->
<cfparam name="URL.timeout" type="numeric" default="1000" />
<!--- Pause the thread. --->
<cfthread
action="sleep"
duration="#URL.timeout#"
/>
<!--- Return JSON success. --->
<cfcontent
type="text/plain"
variable="#ToBinary( ToBase64( SerializeJSON( true ) ) )#"
/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>jQuery AJAX And Timeout Demo</title>
<!-- Linked files. -->
<script type="text/javascript" src="jquery-1.3.1.pack.js"></script>
<script type="text/javascript">
$(
function(){
// Fire off AJAX request.
$.ajax(
{
// Define AJAX properties.
method: "get",
url: "timeout.cfm?timeout=5000",
dataType: "json",
timeout: (2 * 1000),
// Define the succss method.
success: function(){
$( "#response" ).text( "Success!" );
},
// Define the error method.
error: function( objAJAXRequest, strError ){
$( "#response" ).text(
"Error! Type: " +
strError
);
}
}
);
}
);
</script>
</head>
<body>
<h1>
jQuery AJAX And Timeout Demo
</h1>
<p>
Loading AJAX.....
</p>
<p id="response">
<!-- Reponse. -->
</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment