Я использую базовый скрипт $ .get (), чтобы узнать, существует ли запись в базе данных.Вызванная страница возвращает либо да, либо нет в зависимости от того, найдена ли запись.Прямо сейчас он возвращает пустое значение независимо.
Это фрагмент HTML с конкретными полями ввода
<p><label for="participant_id">Please enter the Participant ID:</label>
<cfinput type="text" name="participant_id" value="#attributes.stPages.Content.ParticipantId#" required="yes" message="Enter the Participant ID" />
<cfif Len(trim(attributes.stPages.Content.ParticipantId)) eq 0>
<cfinput type="button" name="checkunique" value="Check if Unique" />
<cfinput type="hidden" name="participant_id_valid" value="false" />
</cfif></p>
Это вызывающий скрипт
$("#checkunique").click(function() {
$.get('participant_id_check.cfm?participant_id=' + $('#participant_id').val(), function(data) {
result = data.replace(/^\s+|\s+$/g,"");
if (result) {
$('#unique-result').text('Your Participant ID is accepted');
} else {
$('#unique-result').text('Your Participant ID has already been used. Please enter another');
}
});
});
Вот страница вызова.Если я позвоню прямо в URL, он будет работать нормально.
<!--- Check the database to ensure that the participant ID entered doesn't already exist (only for new entries). --->
<cfparam name="url.participant_id" default="" type="string" />
<cfquery name="checkID" datasource="#APPLICATION.strConfig.datasource#">
SELECT sessionid
FROM tblsessions
WHERE participant_id = <cfqueryparam cfsqltype="cf_sql_varchar" value="#url.participant_id#" null="no" />
</cfquery>
<!--- No record found; value is unique --->
<cfif Not checkID.RecordCount>
Yes
<cfelse>
No <!--- Record found; value is not unique--->
</cfif>