そのリンクのコード例は次のとおりです。
<!doctype html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width" />
<title>My App</title>
<script src="phonegap.js" type="text/javascript" charset="utf-8"></script>
<script src="jquery.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
$.ajax({
url:"http://www.ryanvikander.com/test.cfc?method=getdata",
success: function(data){
var content = $("#content");
content.html(data);
},
error: function(e){
console.log(e);
}
});
});
</script>
</head>
<body>
<div id="title_bar">Test</div>
This is a test
<div id="content"></div>
</body>
</html>
URLhttp://www.ryanvikander.com/test.cfc?method=getdata
はこれ以上である必要はありません:
<cfcomponent>
<cffunction name="getdata" access="remote" output="false">
<cfreturn "Hello World!" />
</cffunction>
</cfcomponent>
ここで、success
コールバック関数は文字列"Hello World!"
を<div id="content"></div>
関数renderdata()
がクエリを返した場合、クエリ文字列パラメータreturnformat=json
を渡し、必要に応じqueryFormat=column
て ColdFusion にクエリ データを JSON に変換させることができます。返されたデータが JSON でフォーマットされている場合、そのデータを反復処理して、他の Web サイトと同様に HTML をレンダリングできます。