为了账号安全,请及时绑定邮箱和手机立即绑定

您好,当js加入ajax代码后就不能运行了,alert也不可以用,这是什么原因呢?

您好,当js加入ajax代码后就不能运行了,alert也不可以用,这是什么原因呢?

牛魔王的故事 2021-11-10 16:07:55
代码后就不可以用了。求解释啊!昨天调试了一天了,今天又弄了好久,实在是没办法了。代码如下:// JavaScript Documentvar xmlHttp;function sendmsg(s){var messag=""if (s=="2"){message=document.getElementById("message").innerHTML;if(messag==""){alert("请输入内容");return}}}function sendmg(s){var message=""if (s=="2"){message=document.getElementById("message").innerHTML;if(message==""){alert("请输入内容");return}}xmlHttp=GetXmlHttpObject()if (xmlHttp==null){alert ("您好!您的浏览器不支持ajax技术,请升级或使用较新版本的ie浏览器。");return} var url="qingtan_ajax.php"url=url+"?t="+Math.random()xmlHttp.open("POST",url,true); xmlHttp.onreadystatechange=stateChanged xmlHttpRequest.setRequestHeder("Content-Type","application/x-www-form-urlencoded;charset=gb2312");xmlHttpRequest.send("author=阿墨&message="+message+"&touser=默默"); }function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ if (xmlHttp.responseText==""){alert("nothing returned"); }if(xmlHttp.responseText<>"norefresh"){document.getElementById("Layer6").innerHTML=xmlHttp.responseText }} }function GetXmlHttpObject(){var xmlHttp=null;try{// Firefox, Opera 8.0+, SafarixmlHttp=new XMLHttpRequest();}catch (e){// Internet Explorertry{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}catch (e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}}return xmlHttp;}
查看完整描述

2 回答

?
慕的地8271018

TA贡献1796条经验 获得超4个赞

这边写了个实例,源代码如下
<script>
function loadXMLDoc()
{
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=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("msgbox").innerHTML+=xmlhttp.responseText;
}
}
xmlhttp.open("post","getwords.asp" ,true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("yourwords="+document.getElementById("yourwords").value);
return false;
}
</script>
<textarea name="content" cols="30" rows="10" id=yourwords></textarea>
<input type=button onclick="loadXMLDoc()" value="提交">
</form>
<hr>
<div id=msgbox></div>

服务器响应源代码:getwords.asp
<%
response.write Request.form("yourwords")&"<br>"
%>

 


查看完整回答
反对 回复 2021-11-14
?
郎朗坤

TA贡献1921条经验 获得超9个赞

message=document.getElementById("message").innerHTML;这里是不是少了点东西啊

message=document.getElementById("message")[0].innerHTML;你试试

查看完整回答
反对 回复 2021-11-14
  • 2 回答
  • 0 关注
  • 277 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信