UPDATING mySQL db with AjAX

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
krraleigh
Forum Commoner
Posts: 86
Joined: Tue Jul 17, 2007 2:52 pm

UPDATING mySQL db with AjAX

Post 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
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

Re: UPDATING mySQL db with AjAX

Post 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.
mmj
Forum Contributor
Posts: 118
Joined: Fri Oct 31, 2008 4:00 pm

Re: UPDATING mySQL db with AjAX

Post by mmj »

at the end of the createRequestObject put this:

Code: Select all

return ajaxRequest;
Post Reply