mxAjax |
techscreencast.com (Quality Technical Screencast) |
| [ Home ] [ Examples ] [ Project / Download ] [ FAQ / How To] [ Docs/Articles] [ About Me ] |
|
mxAjax UsageCommon ConceptsBase URLThe baseUrl property is required of every tag and is used by the tag to make a request to the serverside. The responding resource (e.g., CFM, html etc.) is responsible for returning the response in the appropriate format (plain text, HTML, XML, JSON etc.) ParametersOverviewEach tag has a common parameters property, composed of name-value pairs that eventually get passed to the URL specified in the baseUrl property. You may specify multiple name-value pairs by separating them with commas. Within each pair, you can also indicate that you want a certain form field value to be inserted at the time the request is made by surrounding the value with curly brackets. Let's look at an example. Assume we want to pass two parameters on the URL, one indicating the make of our automobile and another that is a plain text constant. The value of the make parameter will be inserted at request time. In this case, we assume the makeId form field contains a value of "Honda". parameters="make={makeId},q=someConstantValue"...will be replaced at request time with... parameters="make=Honda,q=someConstantValue" Post-functions and Error FunctionsIf you've wondered how to either chain AJAX tags together--by having one execute after another has completed--then you'll like this. The postFunction attribute allows you do just that. This attribute expects a JavaScript function name to be passed. The AJAX JavaScript will execute the function you define after it has finished its work. In addition to post-functions, you may also define functions to be executed when the AJAX request could not be completed (e.g., invalid URL, server exception). You simply enter the name of the user-defined JavaScript function into the optional errorFunction tag attribute. mxAutocompleteThe autocomplete tag allows one to retrieve a list of probable values from CF and display them in a dropdown beneath an HTML text input field. The user may then use the cursor and ENTER keys or the mouse to make a selection from that list of labels, which is then populated into the text field. This tag also allows for a second field to be populated with the value or ID of the item in the dropdown. <form>
State : <input id="searchCharacter" name="searchCharacter" type="text" size="40" />
<input id="statecode" name="statecode" type="text" size="2" />
</form>
new mxAjax.Autocomplete({
indicator: "indicator",
minimumCharacters: "1",
target: "statecode",
className: "autocomplete",
paramArgs: new mxAjax.Param(url,{cffunction:"getStateList"}),
parser: new mxAjax.CFQueryToJSKeyValueParser(),
source: "searchCharacter"
});
mxPortletThe portlet tag simulates a a href="http://www.jcp.org/en/jsr/detail?id=168"JSR-168/a style portlet by allowing you to define a portion of the page that pulls content from another location using Ajax with or without a periodic refresh. This tag expects an HTML response instead of XML and the AJAX function will not parse it as XML; it will simply insert the content of the response as is.
new mxAjax.Portlet({
executeOnLoad: true,
paramArgs: new mxAjax.Param(url + '?htmlResponse=true',{param:"code=honda", cffunction:"getContent"}),
imageClose: "../core/images/close.png",
imageRefresh: "../core/images/refresh.png",
title: "Demo Portlet",
classNamePrefix: "portlet",
imageMaximize: "../core/images/maximize.png",
imageMinimize: "../core/images/minimize.png",
source: "portlet_1",
refreshPeriod: "5"
});
mxSelectThe select tag allows one to retrieve a list of values from a backend servlet (or other server-side control) and display them in another HTML select box. <form>
<table>
<tr>
<td>
Select a phone brand :
</td>
<td>
<select id="brand" name="brand">
<option value="Nokia">Nokia</option>
<option value="Motorolla">Motorolla</option>
<option value="Samsung">Samsung</option>
</select>
</td>
</tr>
<tr>
<td align="right">
Select a phone model :
</td>
<td>
<select name="model" id="model" style="vertical-align:top;"></select>
</td>
</tr>
</table>
</form>
new mxAjax.Select({
parser: new mxAjax.CFArrayToJSKeyValueParser(),
executeOnLoad: true,
target: "model",
paramArgs: new mxAjax.Param(url,{param:"brand={brand}", cffunction:"makelookup"}),
source: "brand"
});
mxTabPanelProvides a tabbed page view of content from different resources
<div id="tabPanelWrapper">
<div id="tabPanel" class="tabPanel">
<ul>
<li><a href="javascript://" onclick="executeAjaxTab(this, 'code=ford'); return false;"
class="ajaxCurrentTab">Ford</a></li>
<li><a href="javascript://" onclick="executeAjaxTab(this, 'code=honda'); return false;">Honda</a></li>
<li><a href="javascript://" onclick="executeAjaxTab(this, 'code=mazda'); return false;">Mazda</a></li>
</ul>
</div>
<div id="tabContent" class="tabContent"></div>
<p>Page loaded at: <cfoutput>#now()#</cfoutput></p>
</div>
function executeAjaxTab(elem, params) {
var aj_tabPanel = new mxAjax.TabPanel({
paramArgs: new mxAjax.Param(url + '?htmlResponse=true',{param:params, cffunction:"getContent"}),
target: "tabContent",
panelId: "tabPanel",
source: elem,
currentStyleClass: "ajaxCurrentTab"
});
}
mxTabPanel
mxTablePanel - Individual Tab
mxUpdateFieldBuilds the JavaScript required to update one or more form fields based on the value of another single field.
<select id="brand" name="brand">
<option value="Nokia">Nokia</option>
<option value="Motorolla">Motorolla</option>
</select>
Make : <input id="make" name="make" type="text" size="30" />
Model : <input id="model" name="model" type="text" size="30" />
new mxAjax.UpdateField({
parser: new mxAjax.CFArrayToJSArray(),
paramArgs: new mxAjax.Param(url,{param:"brand={brand}", cffunction:"makelookup"}),
target: "make,model",
source: "brand"
});
mxDomIncludemxDOMinclude is replacement for annoying popup windows : If JavaScript is available the linked file gets shown in a new layer - if it is an image just as the image, if not inside an IFRAME. DOMinclude automatically positions the popup where the original link is and adds a text prefix to the original link telling the user how to hide the layer again
function init() {
new mxAjax.DomInclude( {source:"amazon"} );
new mxAjax.DomInclude( {source:"photo"} );
new mxAjax.DomInclude( {source:"content"} );
}
addOnLoadEvent(function() {init();});
Example 1 : <a id="amazon" href="data/amberspyglass.html">Phillip Pullman: The Amber Spyglass</a>
<br><br>
Example 2 : <a id="photo" href="data/saywhat.jpg">Image</a>
<br><br>
Example 3 : <a id="content" href="data/exampleTandC.html">Html Content</a>
|