Home » ColdFusion Ajax Tutorial 4: Partial Page Updates
Ajax type applications allow developers to update parts of a web page without needing to refresh the entire page. Click on a link and another area of the screen is updated, click a toggle arrow to expand and collapse an inline detail box, submit a form and receive confirmation without updating the page, and so on.
This type of interaction uses asynchronous HTTP calls back to the server (to get data, or process form submissions, and so on) and client side JavaScript to update specific parts of a page (usually defined using
tags). ColdFusion 8 makes this type of interaction very simple by allowing controls to be bound to other controls, so that when one control changes (or an event occurs) a second control may be updated by making an asynchronous call to ColdFusion on the server.
To demonstrate this, here is a simple example. A list of art items is displayed in a
How did I guess that. While your at it, can you show us how to rewrite Major BBS, PCBoard, TBBS and Wildcat so those of us that remember those days, can go back to them.
How does this work when Javascript is disabled or not available? The same question applies to all the new cfajax functionality. Thinking here about the accessibility of pages; is the information still available to people using text readers etc, or do we need to roll our own accessible pages using javascript detection etc?
Gary, that tree example was just posted.
Duncan, not very well, and that’s a hole with any and all Ajax stuff, JavaScript is an absolute requirement. Fortunately that’s not as big an issue nowadays, but if it is a concern for your user base, then you’d be best off avoiding anything Ajax.
— Ben
In the documentation that ships with the beta – the cfdiv tag has an example that uses <cfdiv source="page.cfm?urlvar={something}" /> but when I try to use run it I get an error stating ‘required attribute ‘bind’ not provided’ (and I tried putting the page source as the bind attribute but that didn’t work). So how can I do this – is the documentation wrong (pg 887 of the downloadable pdf file).
After a couple of frustrating hours of debugging, I found a problem with binding to a CFC.
This problem happens when you are using the Application.cfc method onRequestEnd() to display content.
Suppose my Application.cfc onRequestEnd() method looks like this:
<cffunction name="onRequestEnd" output="true" returnType="void" description="Runs at the end of a request, after all other CFML code">
<cfargument name="targetPage" type="string" required="yes" />
THIS IS HTML CONTENT in Application.onRequestEnd<br>
</cffunction>
The return from CFC invocation in the bind argument will ALSO return content from the onRequestEnd() method.
I’m working on some code that will display a list of state abbreviations from a list of selected states (checkboxes).
*** IMPORTANT ***
CF8 suggests that you append "cfdebug" to the URL for debugging ajax calls. I wish that I had noticed this before it would have saved me at least 90 minutes.
*** IMPORTANT ***
After appending "cfdebug=1" to the URL, I noticed that it can display the calls to the CFC in real time. This is an awesome debugging tool. The following is an example of what was returned when the onRequestEnd() method used the snippet above:
info:http: CFC invocation response: "KY, ND" THIS IS HTML CONTENT in Application.onRequestEnd
Now see what it looks like when Application.onRequestEnd() does nothing:
info:bind: Assigned bind value: ‘KY, ND’ to StateProvinceList.innerHTML
info:http: CFC invocation response: "KY, ND"
Notice that when there is content in onRequestEnd() that the bind event never occurs. It just gets as far as the CFC invocation response.
So, if you are using onRequestEnd() to display debugging info or other content, I would recommend moving this code to the end of onRequest() or find some other place for it.
I’m trying to run this example and I’m getting th efollowing error:
The ARTID argument passed to the getArtDescription function is not of type numeric.
OK, I have fixed the erorr by adding the selected atribute to the cfselect.
Now there is no error but no description is displayed either.
What I’m doing wrong?
Thx
Can you bind a CFDIV to a cfc with returntype’="query"?
With my setup, using returntype=string, I get just one record, and I should get many.
When I try to use returntype="query" in my cfc I just get "[object Object]" in my div. ??
The problem I’ve run into when binding a cfselect to a cfdiv is when a form in the cfdiv creates a new record, how do you trigger an update of the cfselect’s binding so that the new record is reflected in the cfselect list?
Please solve this problem:
How the ‘cfdiv’ bind with the return value of a function in a same page?
For example:
<!—Page.cfm—>
<cffunction name=’addRecord’>
<!—Function body —>
<cfreturn rtnValue>
</cffunction>
<cfajaxproxy tags=’cfform,cfdiv’ >
<cfform name=’frm’>
<cfinput type=’text’ name=’txtValue’ />
</cfform>
<cfdiv id=’divName’ bind=’addRecord({txtValue})’ />
Hello, I need some help please:I want to make a partial page update from the following:
on top of the page to have a text input box and next to it a search button. When I press the search button this would trigger a cfc (the cfc would query the results from a database based on a keyword entered in the text inputbox) and display the results from the called cfc ON THE SAME PAGE, below the textinput and search button area. How can I do that? Thanks a million for your help!
Hey guys,
Something strange is going on. I am using CF8 and I have multiple records in a table and they all display fine with a table within a cfoutput query="foo". However I want to use cfdiv instead to take advantage of partial page updates.
So I am binding my cfdiv to a cfc and when it runs it only displays the first record. I have had similar problems with using cfoutput query and divs in the past. Is there something about divs that don’t allow multiple results to display?
Here is my code:
——————————————————————————————————
<cfinvoke component="services.PostService" method="getPosts" returnvariable="post">
<cfinvokeargument name="numberOfRows" value="4">
</cfinvoke>
<cfoutput>
<cfdiv bind="cfc:services.PostService.getPosts(4)">
#post.description# <br />
</cfdiv>
</cfoutput>
——————————————————————————————————-
Here is my component in case you need to look at it:
<cfcomponent output="no">
<cffunction name="getPosts" access="remote">
<cfargument name="numberOfRows" type="numeric" required="yes">
<cfset var getPosts = "">
<cfinclude template="../dal/qry_getPosts.cfm">
<cfreturn getPosts>
</cffunction>
</cfcomponent>
Thanks for any help you can provide.
Thank you,
Chris
Hello!,
I have two <cfdivs> on a page: Cfdiv1 and cfdiv2. I have a form in cfdiv1 and wish to update content in cfdiv2 when a submit button is clicked in cfdiv1.
Is this possible with cf8/9? Can someone please show me how to do this?
Thanks in advance.
Hello! I have a question, I am trying to display an image after a selection is made with cfselect…
here is a part of the form where i make the selection:
<cfselect name="pais_id" id="pais_id" required="yes" value="pais_id" display="pais_nom" bind="cfc:pais.getPais()" bindonload="true" />
on the cfc i have…
<cffunction name="DatosPais" access="remote" returnType="any">
<cfargument name="pais_id" type="any" required="true">
<!— Define variables —>
<cfset var data="">
<cfset var result=0>
<!— Get data —>
<cfquery name="data" datasource="enmovimiento">
SELECT pais_foto
FROM paises
WHERE pais_id = #ARGUMENTS.pais_id#
</cfquery>
<!— Convert results to array —>
<cfset result=data.pais_foto>
<!— And return it —>
<cfreturn result>
</cffunction>
I get the filename to display with this…
<cfdiv bind="cfc:pais.DatosPais({pais_id})" />
I would like to know how to display the image…
Any help will be greatly appreciated!
Hello! I have a question, I am trying to display an image after a selection is made with cfselect…
here is a part of the form where i make the selection:
<cfselect name="pais_id" id="pais_id" required="yes" value="pais_id" display="pais_nom" bind="cfc:pais.getPais()" bindonload="true" />
on the cfc i have…
<cffunction name="DatosPais" access="remote" returnType="any">
<cfargument name="pais_id" type="any" required="true">
<!— Define variables —>
<cfset var data="">
<cfset var result=0>
<!— Get data —>
<cfquery name="data" datasource="enmovimiento">
SELECT pais_foto
FROM paises
WHERE pais_id = #ARGUMENTS.pais_id#
</cfquery>
<!— Convert results to array —>
<cfset result=data.pais_foto>
<!— And return it —>
<cfreturn result>
</cffunction>
I get the filename to display with this…
<cfdiv bind="cfc:pais.DatosPais({pais_id})" />
I would like to know how to display the image…
Any help will be greatly appreciated!
Does anybody knows a way to make the content of the <cfdiv> visible for search engine bots?
For instance Google sees the description of an advertiser on my website like this:
<div id="Category">
</div>
But I would like Google to be able to see this:
Chef and owner of the Limassol based restaurant Ta Piatakia (Little Plates) Roddy Damalis has not only stirred up the culinary scene in Cyprus, he also managed to become one of the island’s most celebrated chefs. Ta Piatakia may be categorized as a Cypriot restaurant, but the menu is nothing like that of a local taverna, even though the ingredients are all local, traditional produce.
Am I the only one who has a problem with this side effect of cfdivs?
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie
Duration
Description
cookielawinfo-checkbox-analytics
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional
11 months
The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy
11 months
The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Leave a Reply