首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

asp 提交表单后,采用alert弹出消息框中文出现乱码,该如何解决

2012-05-01 
asp 提交表单后,采用alert弹出消息框中文出现乱码完整贴出代码:!DOCTYPE html PUBLIC -//W3C//DTD XHTML

asp 提交表单后,采用alert弹出消息框中文出现乱码
完整贴出代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title></title>
   
  <link href="cs.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" language="JavaScript">
 
// 表单提交客户端检测
function doCheck(){
if (document.form1.projname.value==""){
alert("项目名称不能为空!");
document.form1.projname.focus();
return false;
}
if (document.form1.contact.value==""){
alert("联系人不能为空!");
document.form1.contact.focus();
return false;
}
if (document.form1.tel.value==""){
alert("电话号码不能为空!");
document.form1.tel.focus();
return false;
  }
  if (document.form1.email.value == "") {
  alert("邮箱地址不能为空!");
  document.form1.email.focus();
  return false;
  }
if (document.form1.summary.value==""){
alert("项目说明不能为空!");
document.form1.summary.focus();
return false;
  }
  //document.form1.submit(); 
}

  // 表单提交客户端检测
  function doSubmit(){
document.form1.submit();
}
function PreviewImgSingle(imgFile)
  {
  var picname,prev_picname;
  var newDate = new Date();
prev_picname = newDate.getFullYear() + ""+(newDate.getMonth() + 1) + "" + newDate.getDate() +"" + newDate.getHours() + "" + newDate.getMinutes() + "" + newDate.getSeconds() +"";
  picname =imgFile.value.substring(imgFile.value.lastIndexOf("\\")+1);
  document.getElementById('d_picname').value = prev_picname+picname;
  //alert(prev_picname+picname);
   

  }
</script>
<style type="text/css">
.deliverform
{
width:430px;
font-size:13px; 
color:#000; 
font-family:Microsoft YaHei;
margin-left:auto; 
margin-right:auto;

}
.txtstyle
{
width:110px; 
height:30px;
float:left; 
text-align:left;
}
.framestyle
{
width:300px; 
height:30px;
text-align:left;
float:left;
}
input
{
width:200px;
border:1px solid #999;
}
.upfile
{
width:270px;
border:1px solid #999;
background-color:transparent;
}
.txtarea
{
width:300px; 
text-align:left;
border:0px;
overflow-x: hidden; /*隐藏多行文本框的水平滚动条*/
float:left;
}
</style>
</head>

<body style="background:url(../images/backlogo1.png) no-repeat right bottom;">
<div class="Main_Frame">
  <div class="Head">
  <!--#include file="head.html"-->
  </div>
  <div class="Middle">
  <form name="form1" action="planupload.asp" enctype="multipart/form-data" method="post" target="hidFrame" onsubmit="return doCheck();">
  <div class="deliverform">
  <div class="txtstyle">项目名称:</div><div class="framestyle"><input name="projname" type="text" class="input" id="projname" />*</div>


  <div class="txtstyle">联&nbsp;系&nbsp;人:</div><div class="framestyle"><input name="contact" type="text" class="input" id="contact" />*</div>
  <div class="txtstyle">联系电话/手机:</div><div class="framestyle"><input name="tel" type="text" class="input" id="tel" />*</div>
  <div class="txtstyle">电子邮箱:</div><div class="framestyle"><input name="email" type="text" class="input" id="email" />*</div>
  <div class="txtstyle">项目说明:</div>
  <div class="txtarea"><textarea name="summary" id="summary" rows="2" cols="10" style="overflow:auto;height:150px;width:290px;border:1px solid #999;background:url(../images/textarea.png) no-repeat right bottom;" ></textarea>*</div>
  <div class="txtstyle" style=" height:8px;">&nbsp;</div><div class="framestyle" style=" height:8px">&nbsp;</div>
   
 
  <div class="txtstyle">创业计划书上传:</div><div class="framestyle">
  <input type="hidden" name="d_picname" id="d_picname" value="" /><input type="file" name="file" id="file" onchange="PreviewImgSingle(this);"/></div>
   
   
  <div class="txtstyle"></div>
  <div class="framestyle"><input type="image" name="image" src="../images/btnsend.png" style="width:59px;height:20px;"/><a href="#"><img alt="" src="../images/btnprint.png" width="59px" height="20px"/></a><a href="index.asp"><img alt="" src="../images/btnreturn.png" width="59px" height="20px"/></a></div> 
  </div>
  </form>
   
  <iframe name="hidFrame" style="display:none"></iframe>
  </div><br /><br />
  <div class="Bottom">
  <!--#include file="menu.html"-->
  </div>
</div>
</body>
</html>


下面是表单提交目标文件planupload.asp:

<!--#include file="../include/config.asp"-->

<!--#include file="upload.inc"--> 

<% 

dim upload,file,formName,formPath,n_postertime
dim picurl,picname,strSQL,piccontent,multipic,pic_id

set upload=new upload_5xSoft ''''建立上传对象
picname = upload.form("d_picname")
picname = upload.form("d_picname")
formPath=upload.form("filepath") ''''在目录后加(/) 

if right(formPath,1)<>"/" then formPath=formPath&"/" 
for each formName in upload.file ''''列出所有上传了的文件 
  set file=upload.file(formName) ''''生成一个文件对象 


  if file.FileSize>0 then ''''如果 FileSize > 0 说明有文件数据
  file.SaveAs Server.mappath("..\uploadfiles\"&picname) ''''保存文件 
   
  end if 
  set file=nothing 
next 


dim projname,contact,tel,email,summary,plan,uptime,sql,nr
projname =trim(upload.form("projname"))


contact =trim(upload.form("contact"))
tel =trim(upload.form("tel"))
email =trim(upload.form("email"))
summary=encode(trim(upload.form("summary")))
picname =trim(upload.form("d_picname"))
uptime=now()
set upload=nothing


sql="INSERT into planinfo (projname,contact,tel,email,descript,filepath,uptime) values('"&projname&"', '"&contact&"', '"&tel&"', '"&email&"', '"&summary&"', '"&picname&"', '"&uptime&"')"

clsdb.dbSQL sql

Response.Write "<script language=javascript>alert('信息提交成功,我们将尽快和你联系,感谢您的参与!');</script>"
'Response.Write "<script language=javascript>alert('file upload ok!');</script>"
Response.End


%>

[解决办法]
charset=utf-8"
你把页面编码改为gkb试试
[解决办法]

探讨
引用:
charset=utf-8"
你把页面编码改为gkb试试


这个应该不行吧,我的文档都是utf-8的呀

不过,我先来试试

[解决办法]
<%Session.CodePage=65001%>
<%
Response.Charset="utf-8"
%>

加上这两句 加在 ASP 的页面最顶部
[解决办法]
我也遇到过类似的问题,是改为这样就好了。
<META http-equiv=Content-Type content="text/html; charset=gb2312">
[解决办法]
检查所有被包含的文件的编码是否是 utf-8,尤其那个上传的程序
[解决办法]
把你ajax接收页,用记事本打开,文件 另存为 utf-8 的格式
[解决办法]
VBScript code
Response.Write "<script language=javascript>alert('信息提交成功,我们将尽快和你联系,感谢您的参与!');</script>"
[解决办法]
页面最顶部加上,

<%
Response.Charset="gb2312"
%>
[解决办法]
编码问题。楼上各位已经给出答案了。
[解决办法]
提交的页面和本页面都统一一下utf-8

热点排行