Forum Moderators: open
function handleResponse() {
if(http.readyState == 4) {
var response = http.responseText;
var sesscheck = "<?php echo $_SESSION['page_num']; ?>";
//if (sesscheck == NULL){
document.write('sesscheck = ', sesscheck);
//}
document.getElementById('foo').innerHTML = response;
}
}
var sndreqtimer = 10000;
setInterval('sndReq()', sndreqtimer);
QUESTION #1...Am I correct in believing that setInterval is still working ok because the document.write('sesscheck gets written?
QUESTION #2 ... If so, then why does the document.getElementById method right after it stop working?
QUESTION #3 ... My need is to get the "if" conditional (just before the document.write) working but uncommenting it seems to cause the setInterval to not work at all (and never call the sndReq function). The initial page just sits there and never loads the target page nor displays the document.write as before. Why does uncommenting the "if" part of the code break everything else?
var sesscheck = "<?php echo $_SESSION['page_num']; ?>";
results in sesscheck containing that string, php can not execute in the clients browser.
Consider doing something like this on php side
echo '<input type="hidden" id="idPageNo" value="' . $_SESSION['page_num']. '">';
use document.getElementById("idPageNo").value in js
document.write should be avoided. Instead, use innerHTML or DOM methods to append to the DOM.