ajax实现无刷新留言的问题,帮我看看这样有错没有?哪里错了.........function showHint()
{
submt();
var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=changecontent;
var text = document.getElementById('area').value;
xmlhttp.open("send","addart.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send(text);
}function changecontent(){
if (4==xmlhttp.readyState){
if (200==xmlhttp.status){
document.getElementById('addtext').innerHTML=xmlhttp.responseText;
}else{
alert("发生错误!");
}
}
}php处理页面
<?
$response = $_REQUEST['text'];
echo $response;?>html页面<div id="addtext" >
qwe
</div><div id="sumit">
<form method="post" name="message" onSubmit="return showHint()">
<table align="center" class="nobrd">
<tr>
<td width="660" colspan="6" align="center" class='brd'><textarea name="area" id="area" style="border:1px dashed #966; height:60px; width:640px; text-align:left; overflow-y:auto"></textarea></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="nobrd" >
<tr>
<td> <input type="submit" value="提交" /></td>
</tr>
</table>
</form>这样写出来的,为什么无法实现,求解释
{
submt();
var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=changecontent;
var text = document.getElementById('area').value;
xmlhttp.open("send","addart.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send(text);
}function changecontent(){
if (4==xmlhttp.readyState){
if (200==xmlhttp.status){
document.getElementById('addtext').innerHTML=xmlhttp.responseText;
}else{
alert("发生错误!");
}
}
}php处理页面
<?
$response = $_REQUEST['text'];
echo $response;?>html页面<div id="addtext" >
qwe
</div><div id="sumit">
<form method="post" name="message" onSubmit="return showHint()">
<table align="center" class="nobrd">
<tr>
<td width="660" colspan="6" align="center" class='brd'><textarea name="area" id="area" style="border:1px dashed #966; height:60px; width:640px; text-align:left; overflow-y:auto"></textarea></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="nobrd" >
<tr>
<td> <input type="submit" value="提交" /></td>
</tr>
</table>
</form>这样写出来的,为什么无法实现,求解释
var str="text="+text........
xmlHttp.send(str);
var Request=new UrlSearch(); //实例化
var sgn = Request.act;
if( sgn !="ace"){
alert("请登录后评论!");
document.login.uname.focus();
return false;
} else { //
if (document.getElementById('area').value== ""){
alert("您的评论不能为空!");
document.message.area.focus();
return false;
};
}
}
<input type="button" value="提交" onclick="return showHint()"/>onSubmit="return showHint()" 这句就可以删掉了。
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send(text=text);