Hi,
This is my first time using the htmlrequest and I'm having a bit of
trouble.
I have a table that looks something like this
NAME STATUS
name1 ... ETK
name2 ... Recruiter
name3 ... ETK
name4 ... Recruiter
The status is a switch that I can press to toggle the value 'status' in
a database. If I press the ETK switch I want the database value changed
to 'ETK' or the equivalent, and the value of the status switch changed
to 'Recruiter' ... thereby pressing the thing again would change it's
value to Recruiter and change the switch back to 'ETK'
I can debug my javascript code no probs. I believe that my problem lies
in my php handler function. It doesn't seem to recognize my
$_GET['action'] variable.
This is a rough version of my php handler function
// get the value of the htmlrequest and call one of two functions based
on that value
if( isset( $_GET['action']) ){
ignore_user_abort();
switch ($_GET['action'])
{
case 'chsts':
change_status($_GET['name']);
exit ;
break;
case 'dete':
delete($_GET['name']);
exit ;
break;
default: exit ;
}
}
My problem is that I can't seem to find out what's going on in my php
code ... there is no page reload so var_dump or echo don't work. How
can I debug php code that is called from a htmlRequest function ?
This is the rest of my code in case you are interested ... this is my
first htmlrequest method.
I'm using a templating system to output my html, my switch looks
something like this.
<td><a
href="javascript:sndReq('chsts','{TEACHER.TEACHER_ NAME}');"
id='{TEACHER.TEACHER_NAME}'>[ETK]</a></td>
This just applies my sndReq function which sends off the htmlRequest in
this form
// send request function
function sndReq(action,name){
http.open('get', 'control_panel.php?action='+action+'&name='+name);
http.onreadystatechange = handleResponse;
http.send(null);
}
I took this code off the internet and made small changes, I believe
it's pretty basic
// build request object
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}
var http = createRequestObject();
This is my response handler ... I'm expecting php to send me back the
strings 'ETK' or 'Recruiter' I then wish to replace the status switch
for the relevant teacher
// handle my response, toggle the value of 'status' between 'ETK' and
'Recruiter'
function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
if(response.indexOf('|' != -1)) {
update = response.split('|');
alert(response);
document.getElementById(update[0]).innerHTML = update[1];
}
}
}
// this is where I change the status in the database, and then output
label the switch with the
// other value ... so that if I want to switch from ETK to Recruiter
.... I'll just have to hit the
// 'Recruiter' switch
function change_status($param)
{
// if I get the 'ETK' value, set status to 0 and set value of switch to
'Recruiter'
if($param=='ETK')
{
$sql_bit='UPDATE TEACHER SET status=0 WHERE name="$param"';
if(!($result=$db->sql_query($sql_bit)))
{
message_die(CRITICAL_ERROR, 'Error doing DB query update status',
'', __LINE__, __FILE__, $sql_bit) ;
}
echo "Recruiter";
}
// if I get the 'ETK' value, set status to 0 and set value of switch to
'Recruiter'
else if($param=='Recruiter')
{
$sql_bit='UPDATE TEACHER SET status=1 WHERE name="$param"';
if(!($result=$db->sql_query($sql_bit)))
{
message_die(CRITICAL_ERROR, 'Error doing DB query update status',
'', __LINE__, __FILE__, $sql_bit) ;
}
echo "ETK";
}
else{
return ;
}
}