我正在使用PHP和AJAX在页面中发帖。以下是该页面的javascript代码。
function Post(posted_by, posted_to)
{
document.getElementById('post_textarea').disabled='disabled';
document.getElementById('post_button').style.display='none';
document.getElementById('loader').style.display='inline';
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttpPost=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttpPost=new ActiveXObject("Microsoft.XMLHTTP");
}
var post=document.getElementById("post_textarea").value;
var params="type=post&posted_by=" + posted_by + "&posted_to=" + posted_to + "&post=" + post //Parameters for post method..
xmlhttpPost.open("POST","test.php",true);
//Send headers; data sent as if it has been posted from form
xmlhttpPost.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttpPost.setRequestHeader("Content-length", params.length);
xmlhttpPost.setRequestHeader("Connection", "close");
xmlhttpPost.onreadystatechange=function()
{
//I can reach here...
if (xmlhttpPost.readyState==4 && xmlhttpPost.status==200)
{
//BUT I CAN'T REACH HERE.. GETTING NO RESPONSE
document.getElementById('posts').innerHTML = xmlhttpPost.responseText + document.getElementById('posts').innerHTML;
document.getElementById("post_textarea").value=""; //Clear textbox
hidePostBox();
}
}
xmlhttpPost.send(params); //Send POST DATA to the server..
}
在PHP文件中,我已经ECHOed一行文本来测试它是否有效。
但我没有把那行文字作为回复。根本没有回应。
我在另一个网站上使用了相同的javascript代码并且它正在运行。这里的代码不起作用。
故障可能是什么?
答案 0 :(得分:2)
好。我从未使用过ERROR CONSOLE。我今天第一次使用它。并发现问题是它没有获取PHP文件,因为我使用了HTACCESS URL重写并且它搞砸了它