中断<cfloop>循环的执行.
<cfajaxproxy
cfc = "CFC name"
jsclassname = "JavaScript proxy class name">
OR
<cfajaxproxy
bind = "bind expression"
onError = "JavaScript function name"
onSuccess = "JavaScript function name">
| 属性 |
必须/可选 |
默认 |
描述 |
|---|---|---|---|
bind |
必选 |
|
指定CFC 方法、JavaScript作用, 或URL 地址表示。对于关于URL地址表示的详细的信息, 参见"Binding 的数据形成fields" 在ColdFusion Developer's 指南。 |
cfc |
必选 | 您必须指定一个对CFC指定一个路径 。路径可能是一绝对filepath, 或相对CFML 页的地点。例如, 如果myCFC CFC 是在ColdFusion 页的cfcs 补充指南, 指定cfcs.myCFC 。 在UNIX 系统下, 标记首先寻找名字或路径的一个文件, 虽然全部是小写。如果没有被发现, ColdFusion 然后寻找确切地对应于属性值的一个文件名或路径, 与字符完全相同。 |
|
| jsclassname | 可选 | CFC的属性 | 名字使用为代表CFC 的JavaScript 的Class。 这个属性无法在函数中使用。 |
onError |
可选 | JavaScript的名字寻找函数, 由函数属性指定失败。作用必须采取二个错误信息: 错误编码和错误信息。 | |
onSuccess |
可选 | JavaScript的名字寻找函数, 由函数属性指定失败。如果函数在CFC内 , 返回值自动地被转换成JavaScript可以理解的意思,在通过对onSuccess 作用之前。 |
<cfajaxproxy cfc="components.emp" jsclassname="emp">
<html>
<head>
<script type="text/javascript">
// Function to find the index in an array of the first entry
// with a specific value.
// It is used to get the index of a column in the column list.
Array.prototype.findIdx = function(value){
for (var i=0; i < this.length; i++) {
if (this[i] == value) {
return i;
}
}
}
// Use an asynchronous call to get the employees for the
// drop-down employee list from the ColdFusion server.
var getEmployees = function(){
// create an instance of the proxy.
var e = new emp();
// Setting a callback handler for the proxy automatically makes
// the proxy's calls asynchronous.
e.setCallbackHandler(populateEmployees);
e.setErrorHandler(myErrorHandler);
// The proxy getEmployees function represents the CFC
// getEmployees function.
e.getEmployees();
}
// Callback function to handle the results returned by the
// getEmployees function and populate the drop-down list.
var populateEmployees = function(res)
{
with(document.simpleAJAX){
var option = new Option();
option.text='Select Employee';
option.value='0';
employee.options[0] = option;
for(i=0;i<res.DATA.length;i++){
var option = new Option();
option.text=res.DATA[i][res.COLUMNS.findIdx('FIRSTNAME')]
+ ' ' + res.DATA[i][[res.COLUMNS.findIdx('LASTNAME')]];
option.value=res.DATA[i][res.COLUMNS.findIdx('EMP_ID')];
employee.options[i+1] = option;
}
}
}
// Use an asynchronous call to get the employee details.
// The function is called when the user selects an employee.
var getEmployeeDetails = function(id){
var e = new emp();
e.setCallbackHandler(populateEmployeeDetails);
e.setErrorHandler(myErrorHandler);
// This time, pass the employee name to the getEmployees CFC
// function.
e.getEmployees(id);
}
// Callback function to display the results of the getEmployeeDetails
// function.
var populateEmployeeDetails = function(employee)
{
var eId = employee.DATA[0][0];
var efname = employee.DATA[0][1];
var elname = employee.DATA[0][2];
var eemail = employee.DATA[0][3];
var ephone = employee.DATA[0][4];
var edepartment = employee.DATA[0][5];
with(document.simpleAJAX){
empData.innerHTML =
'<span style="width:100px">Employee Id:</span>'
+ '<font color="green"><span align="left">'
+ eId + '</font></span><br>'
+ '<span style="width:100px">First Name:</span>'
+ '<font color="green"><span align="left">'
+ efname + '</font></span><br>'
+ '<span style="width:100px">Last Name:</span>'
+ '<font color="green"><span align="left">'
+ elname + '</font></span><br>'
+ '<span style="width:100px">Email:</span>'
+ '<font color="green"><span align="left">'
+ eemail + '</span></font><br>'
+ '<span style="width:100px">Phone:</span>'
+ '<font color="green"><span align="left">'
+ ephone + '</font></span><br>'
+ '<span style="width:100px">Department:</span>'
+ '<font color="green"><span align="left">'
+ edepartment + '</font></span>';
}
}
// Error handler for the asynchronous functions.
var myErrorHandler = function(statusCode, statusMsg)
{
alert('Status: ' + statusCode + ', ' + statusMsg);
}
</script>
</head>
<body>
<form name="simpleAJAX" method="get">
List of Employees:
<select name="employee" onChange="getEmployeeDetails(this.value)">
<script language="javascript">
getEmployees();
</script>
</select>
<br><br>
<span id="empData"></span>
</form>
</body>
</html>
<cfcomponent>
<cfset this.dsn = "cfdocexamples">
<cffunction name="getEmployees" access="remote" returnFormat="json"
output="false">
<cfargument name="empid" required="no" type="string" default="0">
<cfquery name="qryEmp" datasource="#this.dsn#">
select * from Employees
<cfif empid neq 0>
where Emp_ID = #empid#
</cfif>
</Cfquery>
<cfreturn qryEmp>
</cffunction>
</cfcomponent>