<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tricklin &#187; AJAX</title>
	<atom:link href="http://www.patmullin.com/weblog/category/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.patmullin.com/weblog</link>
	<description></description>
	<lastBuildDate>Fri, 24 Sep 2010 14:14:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Sortable List Example With Scriptaculous and PHP/mySQL</title>
		<link>http://www.patmullin.com/weblog/2007/01/05/sortable-list-example-with-scriptaculous-and-phpmysql/</link>
		<comments>http://www.patmullin.com/weblog/2007/01/05/sortable-list-example-with-scriptaculous-and-phpmysql/#comments</comments>
		<pubDate>Thu, 04 Jan 2007 19:26:23 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.patmullin.com/weblog/?p=74</guid>
		<description><![CDATA[After spending a considerable amount of time looking for a decent example of "how to store the newly sorted order of a list after dragging and dropping", I realized that there isn't a whole lot of examples and documentation out there. I've decided that it's my turn to try and come up with a full [...]]]></description>
			<content:encoded><![CDATA[<p>After spending a considerable amount of time looking for
a decent example of "how to store the newly sorted order of
a list after dragging and dropping", I realized that there
isn't a whole lot of examples and documentation out there. 
I've decided that it's my turn to try and come up with a
full blown, easy to understand example using XHTML,
Javascript, PHP, and mySQL.</p>
<p>First off, you'll need both the <a
href="http://script.aculo.us/downloads"
target="_blank">scriptaculous</a> and <a
href="http://script.aculo.us/downloads"
target="_blank">prototype</a> javascript libraries (both
available from <a href="http://script.aculo.us"
target="_blank">script.aulo.us</a>).  Once you've downloaded
these files, you'll need to reference them in the
<code>head</code> of your file:</p>
<p><span id="more-74"></span></p>
<pre class="brush: html">
&lt;script type=&quot;text/javascript&quot;
src=&quot;scripts/prototype.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;scripts/scriptaculous.js&quot;&gt;&lt;/script&gt;
</pre>
<p>Then, in your html file, make your list:</p>
<pre class="brush: html">
&lt;ul id=&quot;items_list&quot;&gt;
	&lt;li id=&quot;item_1&quot;&gt;Item 1&lt;/li&gt;
	&lt;li id=&quot;item_2&quot;&gt;Item 2&lt;/li&gt;
	&lt;li id=&quot;item_3&quot;&gt;Item 3&lt;/li&gt;
&lt;li id=&quot;item_4&quot;&gt;Item 4&lt;/li&gt;
</pre>
<p>Note that the <code>ul</code> and each <code>li</code>
have unique <code>id</code>s.  It is also important to note
that the <code>id</code>s of the list items must have "_#"
at the end (this number must be unique).</p>
<p>Next, add this after the list (because of IE):</p>
<pre class="brush: html">
&lt;script type=&quot;text/javascript&quot;
language=&quot;javascript&quot;&gt;
Sortable.create(&quot;items_list&quot;,{dropOnEmpty:true,con
straint:false});
&lt;/script&gt;
</pre>
<h3>Cool!  It works!  But...</h3>
<p>Now that you've done this, go ahead and check it out. 
Cool...  You can now sort your list by dragging and
dropping!  This is all fine and dandy, but how do I actually
store this new order in my database?</p>
<p>It's pretty simple actually.  In comes "serialize", to
make life easy.  This little gem creates a string containing
information on of the current state of the list being
sorted.  How do you use it?</p>
<pre class="brush: html">
var listorder = Sortable.serialize(&#039;items_list&#039;);
</pre>
<p>Let's say that you've sorted your list as follows:
</ul>
<ul>
<li>item 3</li>
<li>item 2</li>
<li>item 1</li>
<li>item 4</li>
</ul>
<p>When invoked, the variable <code>listorder</code> would
return as
"<code>items_list[]=3&items_list[]=2&items_list[]=1&items_li
st[]=4</code>".  And this is what you need to update your
database.  Notice, the values returned are associated to
whatever is after the underscore (<code>_</code>) in the
<code>id</code> of the list item.</p>
<p>Now that you have this information, you can easily update
your database with a simple <abbr title="Asynchronous
Javascript And XML">AJAX</abbr> call pointing to your php
file ('save_items_order.php' in this case):</p>
<pre class="brush: javascript">
function saveOrder() {
	listorder = Sortable.serialize(&#039;items_list&#039;);
	var url = &#039;save_items_order.php&#039;;
	var pars = listorder
		+ &#039;&amp;rnd=&#039;
		+ new Date().getTime();
	var myAjax = new Ajax.Request(
		url,
		{
			method: &#039;post&#039;,
			postBody: pars,
			onComplete:  showList
		});
}
</pre>
<p>Finally, the PHP/mySQL piece:</p>
<pre class="brush: php">
if($_POST) {
  $items = $_POST[&#039;items_list&#039;];
  $i = 1; # will represent the actual order (starting at 1).
  foreach($items as $itemid) {
    $query = &quot;
      UPDATE items_table SET order_col = $i WHERE id_col =
$itemid
    &quot;;
    mysql_query($query);
    $i++;  # add 1 to the current value of i (the next order
in the list).
  }
}
</pre>
<p>There you have it.  An example of how to sort a list, and
then store the new order in your database.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patmullin.com/weblog/2007/01/05/sortable-list-example-with-scriptaculous-and-phpmysql/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Simple AJAX Example Using ColdFusion</title>
		<link>http://www.patmullin.com/weblog/2006/03/03/simple-ajax-example-using-coldfusion/</link>
		<comments>http://www.patmullin.com/weblog/2006/03/03/simple-ajax-example-using-coldfusion/#comments</comments>
		<pubDate>Thu, 02 Mar 2006 22:54:09 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.patmullin.com/weblog/?p=46</guid>
		<description><![CDATA[As I mentioned in my previous post, I planned on creating a "tutorial that will walk you through a real world working example of AJAX using ColdFusion and a simple MS Access Database." Well, here it is: In order to represent a working example of AJAX, there are a few things we're going to need. [...]]]></description>
			<content:encoded><![CDATA[<p>As I mentioned in my previous <a
href="http://weblog.patmullin.com/?p=46">post</a>, I planned
on creating a "tutorial that will walk you through a real
world working example of <abbr title="Asynchronous
JavaScript and XML">AJAX</abbr> using ColdFusion and a
simple MS Access Database."  Well, here it is:</p>
<p>In order to represent a <a
href="http://www.patmullin.com/view_add_employees.html"
title="Click here to see the AJAX demo live.">working
example</a> of <abbr title="Asynchronous JavaScript and
XML">AJAX</abbr>, there are a few things we're going to
need.</p>
<ul>
<li>database</li>
<li>HTML file</li>
<li>JavaScript (located within the HTML file in this
example)</li>
<li>ColdFusion file (note: any programming language can be
used)</li>
<li>prototype JavaScript library</li>
</ul>
<h3>The Database</h3>
<p>The database used in this example is an extremely basic
MS Access database consisting of one table that contains 6
fields:</p>
<table border="1" cellpadding="6" cellspacing="0"
width="100%">
<thead>
<tr>
<td colspan="2"><strong>Table
Name:</strong>&nbsp;&nbsp;Employee</td>
</tr>
<tr>
<td><strong>Field Name</strong></td>
<td><strong>Data Type</strong></td>
</tr>
</thead>
<tbody>
<tr class="highlight">
<td>EmpID</td>
<td>AutoNumber</td>
</tr>
<tr>
<td>FirstName</td>
<td>Text</td>
</tr>
<tr class="highlight">
<td>LastName</td>
<td>Text</td>
</tr>
<tr>
<td>JobTitle</td>
<td>Text</td>
</tr>
<tr class="highlight">
<td>Phone</td>
<td>Text</td>
</tr>
<tr>
<td>Fax</td>
<td>Text</td>
</tr>
</tbody>
</table>
<p>Now that we know what we are going to be storing, let's
take a look at the "<code>.html</code>" file.</p>
<h3>HTML File</h3>
<p>This file will consist of the form fields needed to
populate the database, along with the placeholder we will
use to show the information being stored:</p>
<pre class="brush: html">
&lt;form name=&quot;addEmployee&quot;&gt;
First Name:&lt;input type=&quot;text&quot;
name=&quot;FirstName&quot; id=&quot;FirstName&quot;
value=&quot;&quot; size=&quot;30&quot; /&gt;
&lt;br /&gt;
Last Name:&lt;input type=&quot;text&quot;
name=&quot;LastName&quot; id=&quot;LastName&quot;
value=&quot;&quot; size=&quot;30&quot; /&gt;
&lt;br /&gt;
Job Title:&lt;input type=&quot;text&quot;
name=&quot;JobTitle&quot; id=&quot;JobTitle&quot;
value=&quot;&quot; size=&quot;30&quot; /&gt;
&lt;br /&gt;
Phone:&lt;input type=&quot;text&quot; name=&quot;Phone&quot;
id=&quot;Phone&quot; value=&quot;&quot; size=&quot;12&quot;
/&gt;
&lt;br /&gt;
Fax:&lt;input type=&quot;text&quot; name=&quot;Fax&quot;
id=&quot;Fax&quot; value=&quot;&quot; size=&quot;12&quot;
/&gt;
&lt;br /&gt;
&lt;input type=&quot;button&quot; name=&quot;submit&quot;
value=&quot;save&quot;
onclick=&quot;insertEmployee();&quot;/&gt;
&lt;/form&gt;
&lt;div id=&quot;EmployeeList&quot;&gt;&lt;/div&gt; 
//placeholder div
</pre>
<p>Notice how there is no <code>method</code> or
<code>action</code> in the <code>form</code> tag?  Both of
these will be taken care of by the JavaScript.</p>
<p><span id="more-46"></span></p>
<h3>The JavaScript</h3>
<p>Once you've gotten all the form fields you need, you're
now ready to start writing the JavaScript that will handle
the <abbr title="Asynchronous JavaScript and
XML">AJAX</abbr> portion.  First, make sure you are
referencing "<a href="http://prototype.conio.net/"
title="Click here to download the latest version of
prototype.js.">prototype.js</a>" (<code>&lt;script
src="/scripts/prototype-1.4.0.js"&gt;&lt;/script&gt;</code>)
.  Now that prototype is in place, we can begin writing the
necessary code to populate the "<code>Employee</code>"
table.  Notice from the xhtml code (above) the
<code>onclick</code> event attached to the save button:
<code>onclick="insertEmployee();"</code>.  This
<code>function</code> is going to be called everytime a user
clicks the "<code>save</code>" button.  Let's take a look at
this function:</p>
<pre class="brush: javascript">
function insertEmployee() {
	// begin form variables
	var fname = $F(&#039;FirstName&#039;);
	var lname = $F(&#039;LastName&#039;);
	var jtitle = $F(&#039;JobTitle&#039;);
	var phone = $F(&#039;Phone&#039;);
	var fax = $F(&#039;Fax&#039;);
	// end form variables
	var url = &#039;employee.cfm&#039;;
	var pars = &#039;FirstName=&#039;
			   + fname
			   + &#039;&amp;LastName=&#039;
			   + lname
			   + &#039;&amp;JobTitle=&#039;
			   + jtitle
			   + &#039;&amp;Phone=&#039;
			   + phone
			   + &#039;&amp;Fax=&#039;
			   + fax
			   + &#039;&amp;Action=Insert&amp;rnd=&#039;
			   + Math.random()*99999;
	var myAjax = new Ajax.Request(
	url,
	{
	        method: &#039;post&#039;,
	        postBody: pars,
	        onComplete: listEmployees
	});
}
</pre>
<p>First of all, we're putting the values within each form
field into variables.  We'll then use these variables to
pass them to the <code>ColdFusion</code> file, which in turn
will insert these values into the database.  The next step
is to declare a variable that will contain the actual URL of
this <abbr title="ColdFusion">CF</abbr> file.  In this
example, we're calling this variable <code>url</code>, and
we're giving it the value of "<code>employee.cfm</code>". 
This value tells us that the <abbr
title="ColdFusion">CF</abbr> file is located in the same
directory as the ".html" file.  Now that we have the values
of each form field and the URL of the <abbr
title="ColdFusion">CF</abbr> file declared, we're going to
create another variable "<code>pars</code>" which will
contain all the name/value pairs that will be passed to the
<abbr title="ColdFusion">CF</abbr> file.  In the code, we've
written these name/value pairs separated by new lines, which
improves readability.  As you can see, these name/value
pairs are passed to the <abbr title="ColdFusion">CF</abbr>
file much like you'd pass them in a URL string.  For
example:</p>
<p class ="blockcode">
employee.cfm?<strong><em>FirstName=John&LastName=Doe&JobTitl
e=Accountant...</em></strong>
</p>
<p>One thing to take note of, however, is the fact that we
are passing 2 additional name/value pairs that are not part
of the form: "<code>Action=Insert</code>" and "<code>rnd=[a
random number]</code>".  The "<code>Action=Insert</code>"
will make sense when we take a closer look at the <abbr
title="ColdFusion">CF</abbr> file.  The "<code>rnd=[a random
number]</code>" is explained in detail in my <a
href="http://weblog.patmullin.com/?p=46">previous
post</a>.</p>
<p>Now that we've got a good understanding of
"<code>pars</code>" and "<code>url</code>", let's take a
look at the actual request that we'll use to send to
back-end:</p>
<pre class="brush: javascript">
    var myAjax = new Ajax.Request(
        url,
        {
            method: &#039;post&#039;,
            postBody: pars,
            onComplete: listEmployees
        });
</pre>
<p>What the above says, is that we're going to open an
<code>XMLHttpRequest</code> that will "<code>POST</code>"
the name/value pairs (<code>pars</code>) to
"<code>employee.cfm</code>".  Then, once the request is
complete, the "<code>listEmployees</code>" function will be
run.  Now that we've got the insert request taken care of,
let's take a look at what the <abbr
title="ColdFusion">CF</abbr> file is doing on the
back-end.</p>
<h3>The ColdFusion File - "employee.cfm"</h3>
<p>We know that we want to populate the database with the
values in the form, and we know that the <abbr
title="Asynchronous JavaScript and XML">AJAX</abbr> request
will be "<code>POST</code>ing" this information.  Since the
request is using the "<code>POST</code>" method, we know
we'll have to use the "<code>FORM</code>" variable (not
<code>URL</code>) for grabbing the parameters being sent. 
Let's take a look at the <abbr title="ColdFusion">CF</abbr>
code:</p>
<pre class="brush: html">
&lt;cfif (IsDefined(&#039;Form.Action&#039;) AND Form.Action
EQ &quot;Insert&quot;)&gt;
    &lt;cflock name=&quot;Insert&quot;
type=&quot;EXCLUSIVE&quot; timeout=&quot;30&quot;&gt;
		        &lt;cfquery name=&quot;insertemployee&quot;
Datasource=&quot;employee&quot;&gt;
			            INSERT INTO Employee (FirstName, LastName,
JobTitle, Phone, Fax)
			            VALUES (&#039;#Form.FirstName#&#039;,
&#039;#Form.LastName#&#039;, &#039;#Form.JobTitle#&#039;,
&#039;#Form.Phone#&#039;, &#039;#Form.Fax#&#039;)
		        &lt;/cfquery&gt;
    &lt;/cflock&gt;
&lt;/cfif&gt;
</pre>
<p>As you can see from the first line, this set of code will
not be run unless the "<code>Action</code>" form parameter
is defined, and that it's equal to "<code>Insert</code>". 
This is where the "<code>&amp;Action=Insert</code>"
name/value pair, added to the "<code>pars</code>" variable
in the JavaScript code, comes into play.  The next set of
code uses a standard SQL statement to insert the data that
is passed into the "<code>Employee</code>" table.  The next
set of code to get run is the query that will select
everything from the "<code>Employee</code>" table, and then
return these values in a table:</p>
<pre class="brush: html">
&lt;cfquery name=&quot;listemployees&quot;
datasource=&quot;employee&quot;&gt;
    SELECT *
    FROM Employee
    ORDER BY LastName
&lt;/cfquery&gt;
&lt;table cellpadding=&quot;4&quot;&gt;
&lt;thead&gt;
    &lt;tr&gt;
        &lt;td&gt;&lt;b&gt;Last Name&lt;/b&gt;&lt;/td&gt;
        &lt;td&gt;&lt;b&gt;First Name&lt;/b&gt;&lt;/td&gt;
        &lt;td&gt;&lt;b&gt;Job Title&lt;/b&gt;&lt;/td&gt;
        &lt;td&gt;&lt;b&gt;Phone&lt;/b&gt;&lt;/td&gt;
        &lt;td&gt;&lt;b&gt;Fax&lt;/b&gt;&lt;/td&gt;
    &lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;cfoutput query=&quot;listemployees&quot;&gt;
    &lt;tr id=&quot;#EmpID#&quot;&gt;
        &lt;td&gt;#LastName#&lt;/td&gt;
        &lt;td&gt;#FirstName#&lt;/td&gt;
        &lt;td&gt;#JobTitle#&lt;/td&gt;
        &lt;td&gt;#Phone#&lt;/td&gt;
        &lt;td&gt;#Fax#&lt;/td&gt;
    &lt;/tr&gt;
&lt;/cfoutput&gt;
&lt;/tbody&gt;
&lt;/table&gt;
</pre>
<p>This table is what gets returned to the
"<code>.html</code>" page.  Remember we said that the
"<code>listEmployees</code>" function would be run when the
request is completed.  It is this function that is
responsible for making this table appear on the page:</p>
<pre class="brush: javascript">
function listEmployees(originalRequest){
    $(&#039;EmployeeList&#039;).innerHTML =
originalRequest.responseText;
    var doc = document.addEmployee;
    doc.FirstName.value = &#039;&#039;;
    doc.LastName.value = &#039;&#039;;
    doc.JobTitle.value = &#039;&#039;;
    doc.Phone.value = &#039;&#039;;
    doc.Fax.value = &#039;&#039;;
}
</pre>
<p>When this function is run, the <code>innerHTML </code>of
the "<code>EmployeeList</code>" placeholder <code>div</code>
will contain the table that was created in
"<code>employee.cfm</code>".  Also added to this function is
the clearing out of all the form fields.</p>
<p>There you have it: an example of inserting information
into a database using <abbr title="Asynchronous JavaScript
and XML">AJAX</abbr> and ColdFusion.  As you can see from
this example, you can use any programming language you
prefer.  The point of this tutorial was to explain the
step-by-step process of using <abbr title="Asynchronous
JavaScript and XML">AJAX</abbr> from front-end to back-end
to front-end again, all without refreshing the users
browser.</p>
<p>You can see this example in action by checking out a
sample <a
href="http://www.patmullin.com/view_add_employees.html">demo
</a> I've created for this tutorial.  In this demo, you will
see a little more functionality.  Feel free to view the
source of this file to see how other functions are
handled.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patmullin.com/weblog/2006/03/03/simple-ajax-example-using-coldfusion/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>My First AJAX Experience</title>
		<link>http://www.patmullin.com/weblog/2006/02/22/my-first-ajax-experience/</link>
		<comments>http://www.patmullin.com/weblog/2006/02/22/my-first-ajax-experience/#comments</comments>
		<pubDate>Tue, 21 Feb 2006 21:12:44 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.patmullin.com/weblog/?p=45</guid>
		<description><![CDATA[All in all, I'd have to say I had a very pleasant experience using AJAX for the first time. The most difficult aspect of working with AJAX, was learning how to implement it. Once I found the right documentation, it was relatively smooth sailing. Getting Started First off, you should download an AJAX library. I [...]]]></description>
			<content:encoded><![CDATA[<p>All in all, I'd have to say I had a very pleasant
experience using <abbr title="Asynchronous JavaScript and
XML">AJAX</abbr> for the first time.  The most difficult
aspect of working with <abbr title="Asynchronous JavaScript
and XML">AJAX</abbr>, was learning how to implement it. 
Once I found the right documentation, it was relatively
smooth sailing.</p>
<h3>Getting Started</h3>
<p>First off, you should download an <abbr
title="Asynchronous JavaScript and XML">AJAX</abbr> library.
 I recommend the <a
href="http://prototype.conio.net/">Prototype</a> javascript
library.   What is prototype.js anyway?</p>
<blockquote><p>Prototype is a JavaScript framework that aims
to ease development of dynamic web applications. Featuring a
unique, easy-to-use toolkit for class-driven development and
the nicest <abbr title="Asynchronous JavaScript and
XML">AJAX</abbr> library around, Prototype is quickly
becoming the codebase of choice for web application
developers everywhere.</p></blockquote>
<p>Basically, a guy named Sam Stephenson spent, I'm sure, an
inordinate amount of time writing this great javascript file
in order to make life easier on all of us.  Using this file
makes writing your <abbr title="Asynchronous JavaScript and
XML">AJAX</abbr> code much easier.  As mentioned earlier,
the hardest part about getting started was finding
documentation.  So, in order to make it simpler for you, I'm
going to include links to the documentation that I used to
get started.</p>
<ul>
<li><a
href="http://www.sergiopereira.com/articles/prototype.js.htm
l">Developer Notes for prototype.js</a> - This documentation
was exactly what I needed, and could quite possibly be the
only thing you'll need.  It contains some really great
examples in the beginning of the document, and the contains
more detailed information later on.  After reading the first
few paragraphs, I was able to get started, and then used the
rest of the document for reference (this part of the
document conveniently happens to be named "Reference for
Prototype.js") haha.</li>
<li><a
href="http://encytemedia.com/blog/articles/2006/02/08/workin
g-with-events-in-prototype">Working With Events In
Prototype</a> - How to use prototype with Keystrokes, Mouse
Clicks, Mouse Hovers, etc.</li>
<li><a
href="http://24ways.org/advent/easy-ajax-with-prototype">Eas
y Ajax with Prototype</a></li>
</ul>
<p><span id="more-45"></span></p>
<h3>What To Watch Out For</h3>
<p>Internet Explorer loves to cache everything.  This is
particularly a problem when you are using <abbr
title="Asynchronous JavaScript and XML">AJAX</abbr>.  What
works well in Firefox, may not seem like it's working in IE.
 I learned this the hard way.  The application I implemented
<abbr title="Asynchronous JavaScript and XML">AJAX</abbr> on
is my personal online checkbook register.  So the idea was
to allow a user to stay on one page, add a new transaction,
submit it, and have the list show the latest transaction
while also changing the account balance all without
refreshing the window.  This worked great in Firefox, yet
nothing seemed to be happening in IE.  When in actuality,
the database inserts were definitely happening, yet the list
and account balance refresh was not.  It took me a while to
figure out what and why this was happening, but finally
figured it out when I came across this article "<a
href="http://www.enja.org/david/?p=25">Ajax IE caching
issue</a>".  It seems as though IE believes that GET
requests (<code>method="get"</code>) need to be cached,
while POST requests do not.  This meant changing all my
requests from GETs to POSTs.  Finding out how to do this
took a bit of research as well, so I'm going to just give
this to you here (if you already know how to do this, then
feel free to ignore the following).  The solution, as you'll
see is extremely simple (changes are marked in <span
class="highlight"><strong><em>bold &amp;
italic</em></strong></span>):<br />
<strong>Example GET request:</strong></p>
<p class="blockcode">
function insertRow() {<br />
		&nbsp;&nbsp;var url = 'ajax_file.cfm';<br />
		&nbsp;&nbsp;var param1 = $F('p1');<br />
                &nbsp;&nbsp;var param2 = $F('p2');<br />
                &nbsp;&nbsp;var param3 = $F('p3');<br />
		&nbsp;&nbsp;var pars = 'P1='<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ param1<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ '&P2='<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ param2<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ '&P3='<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ param3;<br />
		&nbsp;&nbsp;var myAjax = new Ajax.Request(<br />
			&nbsp;&nbsp;&nbsp;&nbsp;url,<br />
			&nbsp;&nbsp;&nbsp;&nbsp;{<br />
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;method: 'get',<br />
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;parameters: pars,<br
/>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;onComplete:
runNextFunction<br />
			&nbsp;&nbsp;&nbsp;&nbsp;});<br />
}
</p>
<p><strong>Example changed to a POST request:</strong></p>
<p class="blockcode">
function insertRow() {<br />
		&nbsp;&nbsp;var url = 'ajax_file.cfm';<br />
		&nbsp;&nbsp;var param1 = $F('p1');<br />
                &nbsp;&nbsp;var param2 = $F('p2');<br />
                &nbsp;&nbsp;var param3 = $F('p3');<br />
		&nbsp;&nbsp;var pars = 'P1='<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ param1<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ '&P2='<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ param2<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ '&P3='<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ param3;<br />
		&nbsp;&nbsp;var myAjax = new Ajax.Request(<br />
			&nbsp;&nbsp;&nbsp;&nbsp;url,<br />
			&nbsp;&nbsp;&nbsp;&nbsp;{<br />
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;method: '<span
class="highlight"><strong><em>post</em></strong></span>',<br
/>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span
class="highlight"><strong><em>postBody</em></strong></span>:
pars,<br />
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;onComplete:
runNextFunction<br />
			&nbsp;&nbsp;&nbsp;&nbsp;});<br />
}
</p>
<p>Well there you have it. The IE issue is fixed, right? 
Well...  Not exactly.  This solution only seemed to work
part of the time.  So, after some more digging, I found the
definitive solution.  Although not elegant, it fixes the
problem.  That solution is to add a random number parameter
onto the end of the parameters that get passed.  "Why would
this work?" you might ask.  Well this random number will
basically fool the browser into thinking it has to return a
page from a URL it's never been to before, rather than
thinking it has it in cache (<a
href="http://www.crackajax.net/cachebust.php">learn
more</a>).</p>
<p><strong>POST Example with Random Number</strong></p>
<p class="blockcode">
function insertRow() {<br />
		&nbsp;&nbsp;var url = 'ajax_file.cfm';<br />
		&nbsp;&nbsp;var param1 = $F('p1');<br />
                &nbsp;&nbsp;var param2 = $F('p2');<br />
                &nbsp;&nbsp;var param3 = $F('p3');<br />
		&nbsp;&nbsp;var pars = 'P1='<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ param1<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ '&P2='<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ param2<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ '&P3='<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ param3;<br />
				    <strong><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+
'&rnd='<br />
				    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+
Math.random()*99999;</em></strong> //using rather large
multiplier to ensure uniqueness<br />
		&nbsp;&nbsp;var myAjax = new Ajax.Request(<br />
			&nbsp;&nbsp;&nbsp;&nbsp;url,<br />
			&nbsp;&nbsp;&nbsp;&nbsp;{<br />
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;method: 'post',<br
/>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;postBody: pars,<br
/>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;onComplete:
runNextFunction<br />
			&nbsp;&nbsp;&nbsp;&nbsp;});<br />
}
</p>
<p>I feel that the information in this article is exactly
what is needed to get your feet wet with <abbr
title="Asynchronous JavaScript and XML">AJAX</abbr>.  I plan
to create a <a
href="http://weblog.patmullin.com/?p=47">tutorial that will
walk you through a real world working example of <abbr
title="Asynchronous JavaScript and XML">AJAX</abbr> using
ColdFusion</a> and a simple MS Access Database.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patmullin.com/weblog/2006/02/22/my-first-ajax-experience/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

