View Full Version : Newbie trying to get AJAX to work

11-12-2008, 04:26 AM
I have the AJAX setup at least I think I do, but for some reason it is creating an error. I highlighted the error in red. the code ...

function createRequestObject(){
var ajaxRequest = false;

// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
return false;

function setPatientValue (theValue) {

var volunteerMemberId = form.volunteerMemberId;
var patientMemberId = form.memberId;

var xmlhttp = createRequestObject();
var obj = document.getElementById(theValue);

xmlhttp.open('get','loadPatient.php?memberId=' + volunteerMemberId+'&patientId='+patientMemberId); xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status = 200) {
obj.innerHTML = xmlhttp.responseText;
if(http.readyState == 4){ //Finished loading the response
/* We have got the response from the server-side script,
let's see just what it was. using the responseText property of
the XMLHttpRequest object. */
var response = http.responseText;



} //end setPatientValue()

The error is telling me that the following is incorrectly coded:

xmlhttp.open('get','loadPatient.php?memberId=' + volunteerMemberId+'&patientId='+patientMemberId);

I am calling the function using:

<a href='findPatient.php' onclick='setPatientValue(patientValues);'>Select Patient</a>

to load this <div>:

<div class='patientValues' id='patientValues'></div

Can you advise?
I have been staring at this code for most of the night and I just can't see any errors.

any insight would be greatly appreciated
Thank You

11-12-2008, 06:57 AM
Nice post, it's the first in awhile I've seen that gives us all the info and a solid description of the problem ;)

That said, can you repost with the exact error message you're getting?

That said, try this first:

xmlhttp.open('get','loadPatient.php?memberId=' + volunteerMemberId+'&patientId='+patientMemberId,false);

You can also add true if you want - it sets the async value (whether or not it's an asynchronous call). It will interpret a non-value as undefined, which isn't exactly the same data type as false so that could be causing the problem.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum