就想点一个图片按钮 然后文本区域写入东西,但是我写的这个怎么显示了马上又被刷掉了,页面好像刷新了。。为什么呢?谁帮我改改 谢谢了
<html>
<head>
<meta http-equiv="Content-Type" content="text/html" charset="utf-8">
<title>留言</title><script type="text/javascript">
var xmlhttp;
//var ii;
function createXMLHttpRequest()
{
if(window.XMLHttpRequest) { //Mozilla 浏览器
xmlhttp = new XMLHttpRequest();
if (xmlhttp.overrideMimeType) {//设置MiME类别
xmlhttp.overrideMimeType('text/xml');
}
}
else if (window.ActiveXObject) { // IE浏览器
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!xmlhttp) { // 异常,创建对象实例失败
window.alert("不能创建XMLHttpRequest对象实例.");
return false;
} }
function biaoqing(i)
{
createXMLHttpRequest();
//ii=i;
// province=document.getElementById("province").value;
//content=document.getElementById("content");alert(i);
if (xmlhttp!=null)
{
var url = "process.php?feelid="+i;
xmlhttp.open("GET",url,true);
//alert(url);
xmlhttp.onreadystatechange=callback;
xmlhttp.send(null);
}
else
{
alert("Your browser does not support XMLHTTP.");
}
}function callback()
{
if (xmlhttp.readyState==4)
{
if (xmlhttp.status==200)
{
var result = xmlhttp.responseText;
alert("result:\t"+result);
document.getElementById("content").innerHTML+=result;
// alert(document.getElementById("content").value);
}
else
{
alert("Problem retrieving XML data");
}
}
}</script>
</head>
<body>
<div>
<p>您的姓名: <input type="text" name="author" size="20"></p>
<p>您的留言内容:</p>
<p>
<input type="image" id="biaoqing" src="1.GIF" onclick="biaoqing(1);" width="15" height="15"/>
</p>
<p> <textarea id="content" name="content" rows="10" cols="30"></textarea></p>
</div>
</body>
</html>process.php
<?php
//header("content = 'text/html; charset=utf-8'");$get=$_GET["feelid"];
//echo $get;
//exit;
//if($get)
//{
$out='<simg>'.$get.'</simg>';
//$out=iconv("utf-8","gb2312//IGNORE",$out);
//echo "你好啊";
echo $out;
//}
?>
问题补充:另外,用火狐就执行 alert("Problem retrieving XML data");这行了。。郁闷 不懂 为什么呢?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html" charset="utf-8">
<title>留言</title><script type="text/javascript">
var xmlhttp;
//var ii;
function createXMLHttpRequest()
{
if(window.XMLHttpRequest) { //Mozilla 浏览器
xmlhttp = new XMLHttpRequest();
if (xmlhttp.overrideMimeType) {//设置MiME类别
xmlhttp.overrideMimeType('text/xml');
}
}
else if (window.ActiveXObject) { // IE浏览器
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!xmlhttp) { // 异常,创建对象实例失败
window.alert("不能创建XMLHttpRequest对象实例.");
return false;
} }
function biaoqing(i)
{
createXMLHttpRequest();
//ii=i;
// province=document.getElementById("province").value;
//content=document.getElementById("content");alert(i);
if (xmlhttp!=null)
{
var url = "process.php?feelid="+i;
xmlhttp.open("GET",url,true);
//alert(url);
xmlhttp.onreadystatechange=callback;
xmlhttp.send(null);
}
else
{
alert("Your browser does not support XMLHTTP.");
}
}function callback()
{
if (xmlhttp.readyState==4)
{
if (xmlhttp.status==200)
{
var result = xmlhttp.responseText;
alert("result:\t"+result);
document.getElementById("content").innerHTML+=result;
// alert(document.getElementById("content").value);
}
else
{
alert("Problem retrieving XML data");
}
}
}</script>
</head>
<body>
<div>
<p>您的姓名: <input type="text" name="author" size="20"></p>
<p>您的留言内容:</p>
<p>
<input type="image" id="biaoqing" src="1.GIF" onclick="biaoqing(1);" width="15" height="15"/>
</p>
<p> <textarea id="content" name="content" rows="10" cols="30"></textarea></p>
</div>
</body>
</html>process.php
<?php
//header("content = 'text/html; charset=utf-8'");$get=$_GET["feelid"];
//echo $get;
//exit;
//if($get)
//{
$out='<simg>'.$get.'</simg>';
//$out=iconv("utf-8","gb2312//IGNORE",$out);
//echo "你好啊";
echo $out;
//}
?>
问题补充:另外,用火狐就执行 alert("Problem retrieving XML data");这行了。。郁闷 不懂 为什么呢?
那怎么还会显示一下内容然后又没了呢??
这不可能啊,不过,觉得楼主先确认一下process.php的提交目录是否正确,是否可以正确输出。
我试了一下,原来你的文本区域是textarea啊
要在textarea里显示内容要用value
即:
把你的
document.getElementById("content").innerHTML+=result;
改成 document.getElementById("content").value+=result; 这样就可以了