[jQuery] AjaxCFC (paging Rey Bango...)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.5730.11" name=GENERATOR></HEAD>
<BODY text=#000000 bgColor=#ffffff>
<DIV dir=ltr align=left><SPAN class=633160814-07022007><FONT face=Arial
color=#0000ff size=2>Don't get me wrong. I'm not returning HTML for the whole
page. I'm ONLY returning the HTML for the affected portion of code. To use my
cookbook as an example...when you add a recipe to your grocery list it performs
a query on all recipes currently in your list (including the new one), then
returns just that string of text for the grocery list
DIV.</FONT></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> discuss-bounces@jquery.com
[mailto:discuss-bounces@jquery.com] <B>On Behalf Of </B>Christopher
Jordan<BR><B>Sent:</B> Tuesday, February 06, 2007 5:21 PM<BR><B>To:</B> jQuery
Discussion.<BR><B>Subject:</B> Re: [jQuery] AjaxCFC (paging Rey
Bango...)<BR></FONT><BR></DIV>
<DIV></DIV><FONT size=-1><FONT
face="Courier New, Courier, monospace">Andy,<BR><BR>That's exactly what I've
done in the past, and in fact was how my first Ajax enabled programs functioned.
Recently though, I've come to realize that if all I need to do is update some
value on a particular area of the screen, I'll have CF return just the value
(presumably calculated or perhaps from a query), and then I'll use jQuery to
update just the portion of the screen that needs to be updated.<BR><BR>For
instance I've got a screen that has three calendars on it. The calendars are
entirely blank (the shells were created with CF, and are just part of the
screen). I have a JS function that accepts the starting month and year and then
makes an ajax call to the server to determine which calendar cells get which
date associated with them. This same function can also accept a number
representing the number of months to move forward or backward (start in January
move forward three months and now you're in April... that sort of thing). When
the data is returned, I have jQuery update just the information in the cells
(which is just text) and it doesn't have to redraw any of the tables that
comprise the calendars.<BR><BR>Hmm... don't know if I explained that too well,
but maybe you get the point.<BR><BR>I've actually been meaning to start a
discussion on this list about different practices in updating the screen.
Specifically, when I've got (for instance) an area of the screen which I'll
refer to as the main container and then an area to the side of that (left or
right, doesn't matter) that contains options. Imagine BlogCFC how the blog
entries are in the main area and there is a side area that contains options or
extra information.<BR><BR>The old way of doing something like this would be to
have frames. A frame on the side for the options and a frame on the right to
hold the main content. Let's say then that the options on the right represent
different functions of the program and thus are really different "screens" or at
least different pages, but you want the content to load in that main container
area -- without a page refresh.<BR><BR>I'm currently doing this for one of my
clients, and I've taken the approach that the main page gets called with a
specific mode or flag and it builds the screen accordingly using jQuery. But
this seems unruly at times. Especially if I'm building a table, I've got
JavaScript building a string of HTML (after the ajax call has returned with the
necessary data) that I'll then send to the content div via jQuery. Is this the
right approach, or is it better to build any HTML like that on the server side
and send it over to be dumped to the screen.<BR><BR>I'm curious how other folks
do this sort of thing... Did I just hijack this thread?
:o)<BR><BR>Chris<BR><BR></FONT></FONT><BR>Andy Matthews wrote:
<BLOCKQUOTE cite=mid01df01c74a3b$aa1c8470$7502010a@dealerskins.loc
type="cite"><META content="MSHTML 6.00.5730.11" name=GENERATOR><!--[if !mso]>
<STYLE>v\:* {
BEHAVIOR: url(#default#VML)
}
o\:* {
BEHAVIOR: url(#default#VML)
}
w\:* {
BEHAVIOR: url(#default#VML)
}
.shape {
BEHAVIOR: url(#default#VML)
}
</STYLE>
<![endif]-->
<STYLE>@font-face {
font-family: Tahoma;
}
@page Section1 {size: 8.5in 11.0in; margin: 1.0in 1.25in 1.0in 1.25in; }
P.MsoNormal {
FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; COLOR: black; FONT-FAMILY: "Times New Roman"
}
LI.MsoNormal {
FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; COLOR: black; FONT-FAMILY: "Times New Roman"
}
DIV.MsoNormal {
FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; COLOR: black; FONT-FAMILY: "Times New Roman"
}
A:link {
COLOR: blue; TEXT-DECORATION: underline
}
SPAN.MsoHyperlink {
COLOR: blue; TEXT-DECORATION: underline
}
A:visited {
COLOR: blue; TEXT-DECORATION: underline
}
SPAN.MsoHyperlinkFollowed {
COLOR: blue; TEXT-DECORATION: underline
}
PRE {
FONT-SIZE: 10pt; MARGIN: 0in 0in 0pt; COLOR: black; FONT-FAMILY: "Courier New"
}
SPAN.EmailStyle18 {
COLOR: navy; FONT-FAMILY: Arial; mso-style-type: personal-reply
}
DIV.Section1 {
page: Section1
}
</STYLE>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<DIV dir=ltr align=left><SPAN class=590510722-06022007><FONT face=Arial
color=#0000ff size=2>Most of the time, I'm using the CFC to do all of the
formatting, then I return a simple string containing all of the HTML that
needs to be applied to the page. For example. take a look at <A
href="http://www.co-opcookbook.com">www.co-opcookbook.com</A>. That's where I
pulled that sample code from.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=590510722-06022007></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=590510722-06022007><FONT face=Arial
color=#0000ff size=2>When you perform a search, it runs the CFC using the
provided keyword. The CFC queries the database, loops over the results, adding
in the appropriate HTML, then returns that long string of text to the
calling JS function.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=590510722-06022007></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=590510722-06022007><FONT face=Arial
color=#0000ff size=2>That might not be the most efficient way of doing things
(if it's not PLEASE someone speak up, I want to get better), but it's the way
that makes sense to me.</FONT></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> <A class=moz-txt-link-abbreviated
href="mailto:discuss-bounces@jquery.com">discuss-bounces@jquery.com</A> [<A
class=moz-txt-link-freetext
href="mailto:discuss-bounces@jquery.com">mailto:discuss-bounces@jquery.com</A>]
<B>On Behalf Of </B>Paul<BR><B>Sent:</B> Tuesday, February 06, 2007 4:05
PM<BR><B>To:</B> 'jQuery Discussion.'<BR><B>Subject:</B> Re: [jQuery] AjaxCFC
(paging Rey Bango...)<BR></FONT><BR></DIV>
<DIV class=Section1>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Andy, this is also
good to know. I guess I’ll figure this out eventually, but what doesn’t
yet make sense is how to handle complex objects (queries, structs) being
returned from the CFC. Do you just handle the formatting in your CFC so
you can pass back (or simply output, I guess) a string and use
$(“#element”).html() to replace the content, or do you handle formatting on
the client side? (By “you” I mean Andy specifically but the rest of you
generally as well…)<O:P></O:P></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><O:P></O:P></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">I’m learning a
lot…<O:P></O:P></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><O:P></O:P></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Paul<O:P></O:P></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><O:P></O:P></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><O:P></O:P></SPAN></FONT></P>
<DIV>
<DIV class=MsoNormal style="TEXT-ALIGN: center" align=center><FONT
face="Times New Roman" color=black size=3><SPAN
style="FONT-SIZE: 12pt; COLOR: windowtext">
<HR tabIndex=-1 align=center width="100%" SIZE=3>
</SPAN></FONT></DIV>
<P class=MsoNormal><B><FONT face=Tahoma color=black size=2><SPAN
style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; COLOR: windowtext; FONT-FAMILY: Tahoma">From:</SPAN></FONT></B><FONT
face=Tahoma color=black size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: windowtext; FONT-FAMILY: Tahoma"> <A
class=moz-txt-link-abbreviated
href="mailto:discuss-bounces@jquery.com">discuss-bounces@jquery.com</A> [<A
class=moz-txt-link-freetext
href="mailto:discuss-bounces@jquery.com">mailto:discuss-bounces@jquery.com</A>]
<B><SPAN style="FONT-WEIGHT: bold">On Behalf Of </SPAN></B>Andy
Matthews<BR><B><SPAN style="FONT-WEIGHT: bold">Sent:</SPAN></B> Tuesday,
February 06, 2007 2:07 PM<BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B>
'jQuery Discussion.'<BR><B><SPAN style="FONT-WEIGHT: bold">Subject:</SPAN></B>
Re: [jQuery] AjaxCFC (paging Rey Bango...)</SPAN></FONT><FONT
color=black><SPAN
style="COLOR: windowtext"><O:P></O:P></SPAN></FONT></P></DIV>
<P class=MsoNormal><FONT face="Times New Roman" color=black size=3><SPAN
style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=blue size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">Just so you know, you
CAN use jQuery to hit the CFC directly. Here's a sample of code I'm
using:</SPAN></FONT><O:P></O:P></P>
<P class=MsoNormal><FONT face="Times New Roman" color=black size=3><SPAN
style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=blue size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">js
code:</SPAN></FONT><O:P></O:P></P>
<P class=MsoNormal><FONT face=Arial color=blue size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">function
addRecipe(id) {<BR> $.get("includes/q.cfc?method=addRecipe&id=" +
id,function(result){<BR> eval( 'var ' + result
);<BR> $('#shoppingList').html(r.content);<BR> });<BR>};</SPAN></FONT><O:P></O:P></P>
<P class=MsoNormal><FONT face="Times New Roman" color=black size=3><SPAN
style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=blue size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">CFC:</SPAN></FONT><O:P></O:P></P>
<P class=MsoNormal><FONT face=Arial color=blue size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial"><cffunction
name="addRecipe" access="remote" returntype="void" hint="Adds a recipe to your
shopping list"><BR> <!--- set parameters for arguments
---><BR> <cfargument name="id" required="Yes"
type="numeric"><BR> <cfset myStruct =
structNew()><BR> <cfif NOT
ListFind(SESSION.grocerylist,id)><BR> <cfset
SESSION.grocerylist =
ListAppend(SESSION.grocerylist,id)><BR> </cfif><BR> <cfset
myStruct["content"] =
Replace(getShoppingList(),"#chr(13)#","","ALL")><BR> <cfwddx
action="CFML2JS" input="#myStruct#"
toplevelvariable="r"><BR></cffunction></SPAN></FONT><O:P></O:P></P>
<P class=MsoNormal><FONT face="Times New Roman" color=black size=3><SPAN
style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></FONT></P>
<P class=MsoNormal><FONT face="Times New Roman" color=black size=3><SPAN
style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></FONT></P>
<P class=MsoNormal><FONT face="Times New Roman" color=black size=3><SPAN
style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></FONT></P>
<P class=MsoNormal><FONT face="Times New Roman" color=black size=3><SPAN
style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></FONT></P><PRE><FONT face="Courier New" color=black size=2><SPAN style="FONT-SIZE: 10pt"><O:P> </O:P></SPAN></FONT></PRE></DIV><PRE wrap=""><HR width="90%" SIZE=4>
_______________________________________________
jQuery mailing list
<A class=moz-txt-link-abbreviated href="mailto:discuss@jquery.com">discuss@jquery.com</A>
<A class=moz-txt-link-freetext href="http://jquery.com/discuss/">http://jquery.com/discuss/</A>
</PRE></BLOCKQUOTE><BR><PRE class=moz-signature cols="72">--
<A class=moz-txt-link-freetext href="http://www.cjordan.info">http://www.cjordan.info</A></PRE></BODY></HTML>
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/