Page 1 of 1

UPDATING mySQL db with AjAX

Posted: Tue Nov 11, 2008 4:24 am
by krraleigh
Can I use the code listed below to send information to a script on my server so that I can use it to update a database?

Code: Select all

 
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 loadPatient (){
 
 var volunteerMemberId = form.volunteerMemberId;
 var patientMemberId = form.memberId;
 
  var http = createRequestObject();
     http.open('get','loadPatient.php?<php?memberId=volunteerMemberId&patientId=patientMemberId ?>');
     http.send(null);
}
</script>
 
<a href='findPatient.php' onclick='loadPatient();'>Select Patient</a>
 
To be honest I hacked this together from several different sites and I am not sure how to test it
I ran a few echos if the values landed on the server file but that won't work because I am not viewing
the file in browser. :roll:
Thank You
Kevin Raleigh

Re: UPDATING mySQL db with AjAX

Posted: Tue Nov 11, 2008 5:21 am
by Ziq
Even if you don't print variables on the screen you can debug script. Create test script like this

Code: Select all

<?php
ob_start();
print_r($_GET);
$content = ob_get_contents();
ob_end_clean();
 
file_put_contents('get.txt', $content);
?>
Now you can see $_GET variables in 'get.txt'. This script can help you.

Re: UPDATING mySQL db with AjAX

Posted: Tue Nov 11, 2008 9:28 am
by mmj
at the end of the createRequestObject put this:

Code: Select all

return ajaxRequest;