PHP JSON & AJAX

1655 ワード

<br> function postComment(){<br> var f = document.comment;<br> var thought = f.thought.value;<br> var url = "process_comments.php";<br> var postStr = "thought="+ thought;<br> var ajax=new XMLHttpRequest();</p>
<pre><code> ajax.open("POST", url, true);
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajax.send(postStr);
ajax.onreadystatechange = function() {
if (ajax.readyState == 4 && ajax.status == 200) {
var errorMessage=ajax.responseText;
document.getElementById('errorMessage').innerHTML=errorMessage;
}
}
}
</code></pre>
<p> Type and save. You know the drill. /* if ($thought_error === true) { echo ""; } */?>