我正在尝试使用 JQuery 和 Coldfusion 从数据库中打印信息,以显示学生的信息及其停车许可证信息,以及与他们在校园内拥有的汽车相关的其他信息。当我尝试加载网页时,我在第 84 行收到一条错误消息:
<cfquery name="q_sample" datasource="cars_live">
有一个意外的标记:“<”。我猜这是因为它已经在 javascript 标签下。有什么办法可以让 JS 和 Coldfusion 一起工作,因为为了从数据库中读取我想要的内容,我需要<cfquery name="q_sample" datasource="cars_live">
和$(this).text()
.
这是学生信息页面的代码。#plates 只是列表的名称,其中包含用户单击的将他们带到此页面的项目。
<div data-role="page" id = 'Student' data-add-back-btn="true">
<div data-role="header">
<h1>Student Info Page</h1>
</div><!-- /header -->
<div data-role="content">
<script type="text/javascript">
$("#plates li").click(function() {
<cfquery name="q_sample" datasource="cars_live">
SELECT FIRST 10 *
FROM veh_rec WHERE LICENSE=$(this).text()
</cfquery>
<cfoutput query="q_sample">
<p>License Plate Number: #license#, <br> Permit ID Number: #decal#, Student ID Number: #ID#</p>
</cfoutput>
});
</script>
</div> <!-- /content -->
</div> <!--/Student -->
如果您需要任何其他信息,请告诉我!
更新 在听取史蒂夫的建议后,这是我的新代码。
乔伊.cfm
<cfparam name="License" default="">
<cfquery name="q_sample" datasource="cars_live">
SELECT * FROM veh_rec WHERE LICENSE=<cfqueryparam cfsqltype="cf_sql_varchar" value="#License#">
</cfquery>
<cfoutput query="q_sample">
<p>License Plate Number: #license# <br> Permit ID Number: #decal#<br> Student ID Number: #ID#</p>
</cfoutput>
部分html文件
<div data-role="page" id = 'Student' data-add-back-btn="true">
<div data-role="header">
<h1>Student Info Page</h1>
</div><!-- /header -->
<div data-role="content">
<script type="text/javascript">
$("#plates li").click(function() {
var strLicense=$(this).text();
$.get("joey.cfm", { license: strLicense})
.done(function(data) {
alert("Data Loaded: " + data);
$("#myResults").html(data);
});
});
</script>
<div id="myResults"></div>
现在唯一的问题是,除非我在“值”区域的车牌中硬编码,否则我无法获得返回值。