我的留言箱项目不能正常工作所以请帮助我。 [英] my message box project is not working so please help me.

查看:62
本文介绍了我的留言箱项目不能正常工作所以请帮助我。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目代码是这个

?>

< html>

< head>

< title>聊天框< / title>

< script>

函数submitChat(){

if(form1.uname。 value = =''|| form1.msg.value = =''){

alert('ALL FIELDS are MANDATORY'!!!');

返回:

}

}

var uname = form1.uname.value;

var msg = form1.msg。值;

var xmlhttp = new XMLHttpRequest();



xmlhttp.onreadystatechange = function(){

if(xmlhttp.readyState = = 4&& xmlhttp.status = = 200){

document.getElementById('chatlogs')。innerHTML = xmlhttp.responseText;

}

}

xmlhttp.open('GET','insert.php?uname ='+ uname +'& msg ='+ msg,true);

xmlhttp.send();





}

< / script>





< / head>

<正文>

<表格名称=form1>

输入您的聊天名称:< input type =textname =uname/>


您的留言:


< textarea name =msg>< / textarea>


< a href =#>发送







加载CHATLOGS请等待.....



< / body>

解决方案

一个明显的错误是:您的< script> 元素放在< head> 元素中。这完全没问题,但这意味着它永远不会被自己执行。只有从外部调用某个函数时才会执行某些操作。它可以从HTML中的某个事件处理程序完成,也可以从脚本中完成,该脚本是< body> 元素的子元素。



此外,在提问时,您需要发布全面且格式正确的代码示例。你的样本不是那样的。它以?> 开头,标签不平衡,依此类推。



- SA

My project code is this
?>
<html>
<head>
<title>Chat Box</title>
<script>
function submitChat(){
if (form1.uname.value= = ' '|| form1.msg.value = = ' '){
alert('ALL FIELDS ARE MANDATORY'!!!');
return:
}
}
var uname = form1.uname.value;
var msg = form1.msg.value;
var xmlhttp = new XMLHttpRequest();

xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState= =4&&xmlhttp.status= =200){
document.getElementById ('chatlogs').innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open('GET','insert.php?uname='+uname+'&msg='+msg,true);
xmlhttp.send();


}
</script>


</head>
<body>
<form name="form1">
Enter Your Chatname: <input type ="text" name="uname"/>

Your Message:

<textarea name="msg"></textarea>

Send




LOADING CHATLOGS PLEASE WAIT....


</body>

解决方案

One apparent bug is this: your <script> element is put in the <head> element. This is perfectly fine, but it means it is never executed by itself. Something will be executed only if you call some function from outside. It can be done from some event handler in HTML, or it can be done from the script which is a child of the <body> element.

Also, when asking questions, you need to post comprehensive and correctly formatted code samples. You sample is not like that. It starts with "?>", tags are unbalanced, and so on.

—SA


这篇关于我的留言箱项目不能正常工作所以请帮助我。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆