Matt here's a quick one using JQuery:

First off, you need to load the JQuery libraries in the head of the page.

<script type="text/javascript">
        $(document).ready(function() {
                $("#button name").live("click", function(){
                        $.ajax({
                                type:"post",
                                url:"url of processing page",
                                data:$("#form name").serialize(),
                                cache:"false",
                                success:
function(){$("#receiving div").load("page to load on sucess")},
                                error: function(){
                                        error functionality here;
                                }
                        });
                });
        )}
</script>

>From the top, 

$(document).ready(function() {

This ensures that everything inside is as soon as the DOM is loaded, while
not as important here, if you're using JQuery for layout manipulation it's
critical, so make a habit of wrapping all JQuery code in it.

$("#button name").live("click", function(){

This script is triggered off of a button, make sure the button tag has an
id, this is what you'll trigger on. 

url:"url of processing page",

this is url of whatever actions you're going to call, hijacks the action
attribute of the form tag

success: function(){$("#receiving div").load("page to load on sucess")},

The page that you want to load after processing, and the div that it should
be placed in

error: function(){error functionality here;}

error functionality, error pages etc.

This is quick and dirty, there's an entire form plugin for JQuery that may
be better suited to what you need.

To debug any AJAX stuff, if you haven't already downloaded Firefox, do it
and get the firebug plugin, along with the JQuery plugins that are
available. The NET tab in firebug will show you all of the behind the scenes
stuff going on.

Hope this helps

sas


-----Original Message-----
From: Matthew Allen [mailto:[email protected]] 
Sent: Friday, January 22, 2010 9:48 AM
To: cf-talk
Subject: AJAX Question


Can anyone please give me pointers or real life example of how to insert
simple form field values into a database using AJAX.

Many thanks.

Matt 



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:330017
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to