Click to See Complete Forum and Search --> : AJAX XMLHttpRequest *.cfm Help
skilled1
04-24-2006, 03:59 PM
looking into using AJAX to do a XMLHttpRequest Object on a *.cfm page, and return that infromation.
Anyone have this script, or know where to get it. I have a very limited knowledge of AJAX, and XML, so any answer will be very helpful.
skilled1
04-24-2006, 04:52 PM
well found the code i was looking for, just need a little help implementing it.
<script language="javascript" type="text/javascript">
var url = "index.cfm?zipmethod=yes&allowCanada=false&zipcode="; // The server-side script function handleHttpResponse() { if (http.readyState == 4) { // Split the comma delimited response into an array results = http.responseText.split(","); document.getElementById('city').value = results[0]; document.getElementById('state').value = results[1]; } }
function trimString (str) {
str = this != window? this : str;
return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
function handleHttpResponse() {
if (http.readyState == 4) {
// Split the comma delimited response into an array
results = http.responseText.split(",");
if((results[1].length > 1))
{
document.Entry.city.value = trimString(results[0]);
document.Entry.day_phone_area.value = trimString(results[2]);
document.Entry.state.value = trimString(results[1]);
document.Entry.night_phone_area.value = trimString(results[2]);
}
changefocus();
}
}
function updateCityState() {
if (document.getElementById('zip').value.length==5)
{
var zipValue = document.getElementById("zip").value;
http.open("GET", url + escape(zipValue), true);
http.onreadystatechange = function() {
if (http.readyState==4) {
handleHttpResponse()
}
}
http.send(null);
}
else {
changefocus();
}
}
function getHTTPObject() {
var xmlhttp;
/*@cc_on
@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@else
xmlhttp = false;
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
}
return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object
function numeralsOnly(evt) {
evt = (evt) ? evt : event;
var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :
((evt.which) ? evt.which : 0));
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
}
return true;
}
</script>