Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Newbie trying to get AJAX to work

    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 ...

    Code:
    function createRequestObject(){
    var ajaxRequest = false;
    
    	try{
    		// Opera 8.0+, Firefox, Safari
    		ajaxRequest = new XMLHttpRequest();
    	} catch (e){
    		// Internet Explorer Browsers
    		try{
    			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    		} catch (e) {
    			try{
    				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;
    		}
    	}
    	xmlhttp.send(null);
    	try
    	{
    		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;
    			
    			//alert(response);
    			if(response!="ok")
    			{
    				alert(response);
    			}
    
    		}
    	}
    	catch(Exception)
    	{
    	;
    	}
    
    }  //end setPatientValue()
    The error is telling me that the following is incorrectly coded:
    Code:
    xmlhttp.open('get','loadPatient.php?memberId=' + volunteerMemberId+'&patientId='+patientMemberId);
    I am calling the function using:
    Code:
    <a href='findPatient.php' onclick='setPatientValue(patientValues);'>Select Patient</a>
    to load this <div>:
    Code:
    <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
    Kevin
    Last edited by krraleigh; 11-12-2008 at 04:29 AM.

  • #2
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    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:
    Code:
    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.
    Feel free to e-mail me if I forget to respond ;)
    ohsosexybrit@gmail.com


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •