この例をできる限り簡略化しました。私はリモート機能を持っています:
<cfcomponent output="false">
<cffunction name="Read" access="remote" output="false">
<cfset var local = {}>
<cfquery name="local.qry" datasource="myDatasource">
SELECT PersonID,FirstName,LastName FROM Person
</cfquery>
<cfreturn local.qry>
</cffunction>
</cfcomponent>
そして、jQuery $ .ajaxメソッドを使用して、すべての人の順序付けられていないリストを作成したいと思います。
<!DOCTYPE HTML>
<html>
<head>
<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1");
</script>
<script type="text/javascript">
jQuery(function($){
$.ajax({
url: "Remote/Person.cfc?method=Read&ReturnFormat=json",
success: function(data){
var str = '<ul>';
// This is where I need help:
for (var I=0; I<data.length; I++) {
str += '<li>' + I + data[I][1]+ '</li>'
}
str += '</ul>';
$('body').html(str);
},
error: function(ErrorMsg){
console.log("Error");
}
});
});
</script>
</head>
<body>
</body>
</html>
私が迷子になっているのは、データをループしているところです。$.getと$.postにはエラートラップがないことを理解しているので、jQuery$.ajaxメソッドを使用することを好みます。
cfcから返されたJSONを処理する方法がわかりません。