表单提交后,将调用 javascript 函数。JS 检查是否有任何数据输入到字段中。成功后,加载此 CF 页面。该页面是一个ajax 加载,这就是我不使用#form.value# 的原因。
查询是什么让我感到困惑。我已经多次运行其余代码,唯一出现错误的时间是 itemtitle 行添加到查询中:
<cfset fieldList = url.searchFields>
<cfset fieldArray = listToArray(fieldList)>
<!--- The fieldArray has the form field names and values in a one-dimensional array
so every odd index is a title and every even index is a value. Hence the step=2 ---
<cfloop index="testing" from="1" to=#ListLen(fieldList)# step="2">
<cfif fieldArray[testing] is 'searchID'>
<cfset itemid = fieldArray[testing + 1]>
<cfoutput>itemid = #itemid#</cfoutput>
</cfif>
<cfif fieldArray[testing] is 'searchName'>
<cfset itemtitle = fieldArray[testing + 1]>
<cfoutput>itemtitle = #itemtitle#</cfoutput>
</cfif>
<cfoutput>#fieldArray[testing]# #fieldArray[testing + 1]#</cfoutput>
</cfloop>
<cfquery name="searchItems" datasource="#thedb#">
SELECT *
FROM spp_items
WHERE avail_mode LIKE '0'
<cfif isDefined('url.categoryID')> AND categoryid = #url.categoryID#</cfif>
<cfif isDefined('itemid')> AND itemid = #itemid#</cfif>
<!--- if I comment this next line out, the query works fine --->
<cfif isDefined('itemtitle')> AND itemtitle LIKE #itemtitle#</cfif>
</cfquery>
为什么我的查询不起作用?再次,我检查了表单提交、js 函数和coldfusion 语法是否都有效。只有当这条线被添加到查询中时,它才会中断。谢谢。