I'm having trouble implementing an AJAX-driven "one-liner" board. For some reason when the user tries to post something to the board, the page hangs. My debugging alerts aren't even firing. I can't figure out why this is happening. Can someone take a look at this? Thanks. The code for the script is below. When the user clicks a button, "write()" fires. If you want to see the script in its natural habitat, go to http://friendblastr.com/sandbox/ and log in with the ID 201921563 Much thanks. var padder = getXmlHTTP(); var date = ""; function write() { alert("Click"); document.getElementById("writeButton").value="Writing..."; if(padder.readyState==0) { alert("Requesting."); line = document.getElementById("line").value; padder.open("POST", "write.php5", true); padder.onreadystatechange = writing; padder.send("line="+encodeURIComponent(line)); } else setTimeout('write()', 1000); } function writing() { alert("State:" + padder.readyState); if(padder.readyState==4) { alert("Got response."); read(); document.getElementById("line").value = ""; document.getElementById("writeButton").value="Write it!"; padder = getXmlHTTP(); } } function read() { if(padder.readyState==0) { padder.open("POST", "read.php5", true); padder.onreadystatechange = reading; padder.send("date="+encodeURIComponent(date)); } else setTimeout('read()', 1000); } function reading() { if(padder.readyState==4) { lines = padder.responseText.split("\n"); for (i = 0; i < lines.length-1; i++) document.getElementById("pad").innerHTML += lines[i]; date = lines[lines.length-1]; padder = getXmlHTTP(); } } function getXmlHTTP() { var obj; try { obj = new XMLHttpRequest(); } catch (e) { try { obj = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { obj = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("This website will not work for you because your browser does not support AJAX.\nPlease update your browser (Firefox is recommended) and try again."); } } } return obj; } read(); Code (markup):
See, my code here: http://ajaxforums.net/index.php?PHPSESSID=c162e0f555458430464217356cecec26&topic=871.0
I checked out your code and modified mine accordingly, but it's still doing the same thing. :-/ The thing that really bugs me is that it's not even executing my "alert" statements. I have one as the first statement in the onClick handler and even THAT isn't going off! var padder = getXmlHTTP(); var date = ""; function write() { alert("writing..."); document.getElementById("writeButton").value="Writing..."; line = document.getElementById("line").value; padder.open("POST", "write.php5", true); padder.setRequestHeader("Content-type","application/x-www-form-urlencoded"); padder.onreadystatechange = writing; padder.send("line="+encodeURIComponent(line)); } function writing() { if(padder.readyState==4) { if (padder.status==200) { padder = getXmlHTTP(); read(); document.getElementById("line").value = ""; document.getElementById("writeButton").value="Write it!"; } else { alert("Error writing! Try again.") document.getElementById("writeButton").value="Write it!"; } } } function read() { padder.open("POST", "read.php5", true); padder.onreadystatechange = reading; padder.send("date="+encodeURIComponent(date)); } function reading() { if(padder.readyState==4) { lines = padder.responseText.split("\n"); for (i = 0; i < lines.length-1; i++) document.getElementById("pad").innerHTML += lines[i]; date = lines[lines.length-1]; padder = getXmlHTTP(); } } function getXmlHTTP() { var obj; try { obj = new XMLHttpRequest(); } catch (e) { try { obj = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { obj = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("This website will not work for you because your browser does not support AJAX.\nPlease update your browser (Firefox is recommended) and try again."); } } } return obj; } read(); Code (markup): Thanks.
That looks nothing like my code. I'd also change the function names. "write" is a JavaScript reserved word.
Yeah... I just tried to take the essential differences between your code and mine and incorporate them into my code. And yeah, probably should change "write" to "post" or something... I'll try coying your code and just modifying it a little and see how that works. Thanks.