This has to be a Jquery question. The following code is returning zero. When I test/debug, I can say without a doubt that the cffunction is generating the number 18.
The success alert shows “Dupe Group-2 count=0”. The Firebug response shows;
{“COLUMNS”:[“DUPECOUNTER”],”DATA”:[[“0”]]}
if ($(e.target).is(":checked")) {
$firstTD = $(this).parent().siblings().first();
SaveDupeGroup = $firstTD.text();
$.ajax({
type: 'GET',
url: 'cfc/basic.cfc?method=CheckDupeGroup&returnformat=json',
dataType: 'json',
data: 'dupegrouptocheck=' + $firstTD.text(),
error: function (xhr, textStatus, errorThrown) {
// show error
alert(errorThrown);
},
success: function (response, textStatus, jqXHR) {
alert('Dupe Group-' + SaveDupeGroup + ' count=' + response.DATA[0]);
ReInitAnswer = confirm('All of the names in this group have been checked.\nDo you want to remove them from the list?');
if (ReInitAnswer) {
alert('continued');
} else {
alert('canceled');
return false;
}
}
});
}
<cffunction name="CheckDupeGroup" output="false" access="remote">
<cfargument name="DupeGroupNumber" required="True" type="string" default="" />
<cfset var qResults = "" />
<cfquery name="qResults" datasource="#request.dsn#">
SELECT COUNT(id) AS DupeCounter
FROM Temp_Duplicate_Individuals_AddressZipState
Where dupe_group_number = #val(arguments.DupeGroupNumber)# and isnull(not_dupe_flag,'False') = 'False'
</cfquery>
<cfreturn (qResults) />
</cffunction>
You’re passing
data: 'dupegrouptocheck=' + $firstTD.text(), but the argument name in the function isDupeGroupNumber. ChangedupegrouptochecktoDupeGroupNumber.The reason this isn’t throwing a required argument error is because you have a default value (an empty string) for the argument, and CF will use the default value rather than throwing an error for not passing in the argument.
So, you are essentially running:
Because you don’t have a
dupe_group_numberthat equals"", the query is correctly returning a count of 0.