Yep, thats how I first learned to do it. HeadStart Ajax was awesome for
giving me the fundamentals.
Here's how you'd do it in Jquery:
$.ajax({type: "POST",
url: "myurl.cfm",
data: param + "&ms=" + new Date().getTime(),
dataType: "html",
success: function(msg){
$("#searchResults" ).empty().append(msg);
}
});
Kevin Aebig wrote:
> Here's a painfully simple implementation. If you are comfortable in JS, than
> all this should make sense to you and if there's something you don't
> understand, send me an offlist message... watch for wrap.
>
> Usage:
> sendAjaxRequest("myurl.cfm", JSFunction, JSObjectAsParameters)
>
>
> <script type="text/javascript">
> <!--
> function GetXmlHttp() {
> var xmlhttp = false;
> if (window.XMLHttpRequest)
> {
> xmlhttp = new XMLHttpRequest()
> }
> else if (window.ActiveXObject)// code for IE
> {
> try
> {
> xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")
> } catch (e) {
> try
> {
> xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
> } catch (E) {
> xmlhttp=false
> }
> }
> }
> return xmlhttp;
> }
>
> function sendAjaxRequest(url, statusCallback, paramsObject)
> {
> var xmlhttp = new GetXmlHttp();
> //now we got the XmlHttpRequest object, send the request.
> if (xmlhttp)
> {
> xmlhttp.onreadystatechange = function ()
> {
> var functionToCall = statusCallback + '(\'\', false)';
> //
> if (xmlhttp && xmlhttp.readyState==4)
> {//we got something back..
> if (xmlhttp.status==200)
> {
> //Return this to handle your own parsing...
> var responseText = xmlhttp.responseText;
> var response = eval(xmlhttp.responseText);
> //
> if (typeof(response) == "object") {
> functionToCall = statusCallback + '(response, true)';
>
> }
> } else {
>
> functionToCall = statusCallback + '(\'\', false)';
> }
> }
> else {
> functionToCall = statusCallback + '(\'\', false)';
> }
> eval(functionToCall);
> }
> // Generate parameters string
> //
> var sendVars = "";
> for (var i in paramsObject) {
> sendVars += i+"="+escape(paramsObject[i])+"&";
> }
>
> // Generate and send request
> //
> xmlhttp.open("POST",url,true);
> xmlhttp.setRequestHeader('Content-Type',
> 'application/x-www-form-urlencoded');
> xmlhttp.send(sendVars);
> }
> }
> -->
> </script>
>
> !k
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four
times a year.
http://www.fusionauthority.com/quarterly
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:255849
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4