I have a test code that works, at least partially, returning data from cfc using ajax call on click
here is the code:
<script type="text/javascript">
$(document).ready(function(){
$('#showteams').click(function() {
$.ajax({
url: "test.cfc?method=getAllTeams&returnformat=JSON",
dataType: 'json',
data: { startrow: "10", endrow: "10" },
success:function(data) {
$.each(data, function(i,team){
$('#teamList').append('<li><a href="#">' + team[0] + '</a> this is the username ' + team[1] + ' ----- name --- ' + team[2] + '');
});
}});
});
$('#teams').show();
$('#teamList').fadeIn(1200);
$(this).attr('disabled', 'disabled');
});
</script>
and a simple cfc (the final one will be much more complex but also flexible enough to be changed when needed)
<cfcomponent output="false">
<cffunction name="getAllTeams" access="remote" output="false" returntype="any">
<cfargument name="startrow" required="yes" type="any">
<cfargument name="endrow" required="yes" type="any">
<cfargument name="cat" required="no" type="any" hint="add later with the rest of the code">
<cfquery name="qGetAllTeams" datasource="datasource">
SELECT ID,NAME,LASTNAME
FROM table
</cfquery>
<cfset one=arraynew(1)>
<cfset two=arraynew(1)>
<cfloop query="qGetAllTeams" startrow="#arguments.startrow#" endrow="#arguments.endrow#">
<cfset one[1]=ID>
<cfset one[2]=NAME>
<cfset one[3]=LASTNAME>
<cfset ArrayAppend(two,#one#)>
</cfloop>
<cfreturn two />
</cffunction>
</cfcomponent>
the code above works but displays only the first 10 records because values are set manually within - data: { startrow: "10", endrow: "10" }, in javascript
while I can easily build this or any sort of paging using only server side code the entire javascript is confusing me here and have no idea how to sort it out. What ever I try in cfc, to mathematically calculate startrow and endrow to be used in cfloop (curently i just put startrow="#arguments.startrow#" endrow="#argumentsendrow#" though this should be changed obviously :) ) it return only the first 10 records because startrow is set to 10 in javascript. I am definitely missing some basic logic here and would really appreciate your help on this one.