Jquery 未从$.get()提取结果
我使用基本的$.get脚本来检索数据库中是否已经存在记录。调用的页面根据是否找到记录返回yes或no。现在,它返回一个空值 这是带有特定输入字段的HTML片段Jquery 未从$.get()提取结果,jquery,coldfusion,Jquery,Coldfusion,我使用基本的$.get脚本来检索数据库中是否已经存在记录。调用的页面根据是否找到记录返回yes或no。现在,它返回一个空值 这是带有特定输入字段的HTML片段 <p><label for="participant_id">Please enter the Participant ID:</label> <cfinput type="text" name="participant_id" value="#attributes.stPages.Con
<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>
这是呼叫页面。如果我直接在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>
您没有使用$。若要正确获取,请尝试以下操作:
$("#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');
}
});
});
还有一点,你的id='participant_id'没有任何东西,所以$'participant_id'。val可能不会给你任何东西不,虽然OP发布的不是一个好方法,但它仍然有效。Coldfusion会根据name属性包含的任何内容自动生成id属性。@Neal这可能是这里的关键!编辑或不编辑。不管怎样,正确使用get是一个独立的问题;两种形式都可以。脚本现在可以正常工作了,但我仍然得到一个空白结果。尝试调试是否是ColdFusion问题。
$("#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');
}
});
});