stockton Posted April 29, 2009 Share Posted April 29, 2009 The following very simple scenario is not working for me. Please help. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html> <title>Test PHP Semaphore</title> <meta name="author" content="Alf Stockton"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="Mon, 22 Jul 2000 11:12:01 GMT"> <script language="JavaScript" type="text/javascript" src="js/Diva.js"></script> </head> <body> <center> <h2>Test PHP Semaphore</h2> </center> <form action="semaphoreTest.php" method="get" name="SemaphoreTest" id="SemaphoreTest" onSubmit='return false;' > <center> <input type=hidden name="submit1" id="submit1" value="<?php echo $Ding; ?>" > <P> <input type=submit value="Submit" onclick="submit_click()"> </p> <div id="Boodskap";></div> <!-- <input type=text readonly name="Boodskap" id="Boodskap" value ='<?php echo $Message ?>'>; --> </center> </FORM> </body> </html> <script language=javascript> function submit_click() { alert "submit_click()"; var bError = false; var strErrorMsg = ""; var Command = "semaphoreTest.php"; progExe(Command); return false; } the semaphoreTest.php looks like:- <?php { $intKey = GUUIDtoInt('b6379c52-d96d-418b-83c3-8aedb5e6cf95'); // echo "Testing semaphore code<br/>"; if (!$sem_id = sem_get($intKey)) { $Message="\nX\n\nCould not get ID for the semaphore."; echo $Message; exit; } else { $Message="\nX\n\nGot semaphore ID; acquiring..."; flush(); if (!sem_acquire($sem_id)) { $Message.=" failed."; echo $Message; exit; } else { $Message="\nX\n\nOK got it. Sleeping for 20 seconds, then releasing."; flush(); sleep(20); sem_release($sem_id); $Message.="Semaphore released. Other scripts should be able to get it now.";i echo $Message; exit; } } } ?> and the Diva.js is:- function getXMLHttpRequest () { try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}; try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}; try { return new XMLHttpRequest(); } catch(e) {}; return null; } // Make the XMLHttpRequest object var xhr = getXMLHttpRequest(); function progExe(CommandString) { xhr.open("GET", CommandString, true); xhr.onreadystatechange = ServerResponse; xhr.send(null); } function ServerResponse() { alert("entered ServerResponse()"); /* The full list of the readyState values is as follows: * 0 (uninitialized) * 1 (loading) * 2 (loaded) * 3 (interactive) * 4 (complete) */ if(xhr.readyState == 0) { document.getElementById("Boodskap").innerHTML = "Uninitialized........"; } else if(xhr.readyState == 1) { document.getElementById("Boodskap").innerHTML = "Loading........"; } else if(xhr.readyState == 2) { document.getElementById("Boodskap").innerHTML = "Loaded........"; } else if(xhr.readyState == 3) { document.getElementById("Boodskap").innerHTML = "Interactive........"; } else if(xhr.readyState == 4) { if (xhr.status == 200) { var parts = xhr.responseText.split("\n"); if (parts[1] == "X") { alert(parts[3]); } else window.location=parts[3]; document.getElementById("Boodskap").innerHTML = ""; } } } Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 29, 2009 Share Posted April 29, 2009 Define not working. Which part is failing? Or what's not working? Quote Link to comment Share on other sites More sharing options...
stockton Posted April 30, 2009 Author Share Posted April 30, 2009 Theoretically I should see messages pop up in the HTML page but nothing occurs. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 30, 2009 Share Posted April 30, 2009 function ServerResponse() { alert("entered ServerResponse()"); /* The full list of the readyState values is as follows: * 0 (uninitialized) * 1 (loading) * 2 (loaded) * 3 (interactive) * 4 (complete) */ if(xhr.readyState == 0) { document.getElementById("Boodskap").innerHTML = "Uninitialized........"; } else if(xhr.readyState == 1) { document.getElementById("Boodskap").innerHTML = "Loading........"; } else if(xhr.readyState == 2) { document.getElementById("Boodskap").innerHTML = "Loaded........"; } else if(xhr.readyState == 3) { document.getElementById("Boodskap").innerHTML = "Interactive........"; } else if(xhr.readyState == 4) { if (xhr.status == 200) { var parts = xhr.responseText.split("\n"); if (parts[1] == "X") { alert(parts[3]); } else window.location=parts[3]; document.getElementById("Boodskap").innerHTML = ""; } } } Question - does the first alert in that function work? Quote Link to comment Share on other sites More sharing options...
stockton Posted April 30, 2009 Author Share Posted April 30, 2009 No it does not. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 30, 2009 Share Posted April 30, 2009 Instead of assigning onreadystatechange to ServerResponse, what if you dynamically create the function there? xhr.onreadystatechange = function() { // put ServerResponse code here } Would that work? Did you get the alert from submit_click function? Quote Link to comment Share on other sites More sharing options...
stockton Posted April 30, 2009 Author Share Posted April 30, 2009 Still nothing. Not even an alert from the submit_click() javascript function. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 30, 2009 Share Posted April 30, 2009 Try with this: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html> <title>Test PHP Semaphore</title> <meta name="author" content="Alf Stockton"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="Mon, 22 Jul 2000 11:12:01 GMT"> <script language="JavaScript" type="text/javascript" src="js/Diva.js"></script> </head> <body> <center> <h2>Test PHP Semaphore</h2> </center> <form action="semaphoreTest.php" method="get" name="SemaphoreTest" id="SemaphoreTest" onSubmit="return submit_click();"> <center> <input type=hidden name="submit1" id="submit1" value="<?php echo $Ding; ?>" > <P> <input type=submit value="Submit"> </p> <div id="Boodskap";></div> <!-- <input type=text readonly name="Boodskap" id="Boodskap" value ='<?php echo $Message ?>'>; --> </center> </FORM> </body> </html> <script type="text/javascript"> function submit_click() { alert("submit_click()"); var bError = false; var strErrorMsg = ""; var Command = "semaphoreTest.php"; progExe(Command); return false; } </script> Quote Link to comment Share on other sites More sharing options...
stockton Posted April 30, 2009 Author Share Posted April 30, 2009 I have removed the " onSubmit='return false; " from the form definition in the html and now I get the final message but not those messages inbetween. The form definition now looks like:- <form action="semaphoreTest.php" method="get" name="SemaphoreTest" id="SemaphoreTest" > The messages I am also expecting but not getting are:- "Uninitialized........" "Loading........" "Loaded........" and "Interactive........" from the Diva.js script. BTW You can actually see the programs/scripts in action at http://www.stockton.co.za/semaphoreTest.html Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 30, 2009 Share Posted April 30, 2009 Sorry, I meant replace all the HTML you have with the one I posted. I thought it was implicit. I guess not. Quote Link to comment Share on other sites More sharing options...
stockton Posted April 30, 2009 Author Share Posted April 30, 2009 OK I missed your implied replace and have now done that and am getting the results I wanted. Thank you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.