Skip to main content
Inspiring
January 28, 2010
Question

question regarding $.ajax()...

  • January 28, 2010
  • 1 reply
  • 353 views

Hi,

I have a simple ajax function (see code below) that submits a very  simple form to a proceess page (TestJQueryProcess.cfm). My question is: Is there  a way to return a message that tells exactly what kind of error occurs on the  process page (TestJQueryProcess.cfm)?

Because all I get from the "status"  argument of the "error : function (data, status) {} "  function is "error" when  something goes wrong in TestJQueryProcess.cfm.

Many thanks in  advance.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Ajax Form</title>

<script type="text/javascript" src="/_lib/jquery.js"></script>
<script language="javascript">
       
function submitForm() {
               
var fName = $.trim($("input#firstName").val());
               
var lName = $.trim($("input#lastName").val());
                $
.ajax({
                        type
: "POST",
                        url
: "TestJQueryProcess.cfm",
                        data
: {firstName: fName, lastName: lName},
                        success
: function (data, status) {
                                alert
($.trim(data));
                       
},
                        error
: function (data, status) {
                                alert
("An error occurred. Unable to process target page.");
                       
}
               
});
       
}
</script>

</head>

<body>
<form name="myform" id="myform">
   
<input name="firstName" id="firstName"><br />
   
<input name="lastName" id="lastName">
</form>
<a href="javascript:submitForm()">Submit Form</a>               
</body>
</html>


In TestJQueryProcess.cfm:
<cfsetting showdebugoutput="false" enablecfoutputonly="true">
<cfoutput>Echo: #form.firstName# #form.lastName#</cfoutput>

This topic has been closed for replies.

1 reply

Inspiring
January 29, 2010

data.responseText is what I need.