当前位置: 代码迷 >> Java Web开发 >> document.form1.submit() 揭示拒绝访问
  详细解决方案

document.form1.submit() 揭示拒绝访问

热度:11530   发布时间:2013-02-25 21:12:33.0
document.form1.submit() 提示拒绝访问
各位大侠 请教各位下 我这里提交form表单 为什么提示拒绝访问呢 代码我贴下边了
function importExcel(){
  var fileObj=document.all.filepath;
  fileObj.click();
  var filePath = fileObj.value; 
  if(filePath=="") return; 
  //alert("filePath======"+filePath);
  if(null!=filePath && ""!=filePath){
var ext=filePath.substring(filePath.lastIndexOf(".")+1,filePath.length);

if(ext!="xls"){
alert("你选择的不是Excel文件");
return false;
}else{
var aa=filePath.substring(0,filePath.lastIndexOf("."));//截取"."之前的路径
var name=aa.substring(aa.lastIndexOf("\\")+1); //截取名字

var name=filePath.substring(filePath.lastIndexOf("\\")+1);
method="read";
var url="upload.jsp?method="+method+"&name="+name;
document.form1.action=url;
alert(document.form1.submit());
document.form1.submit();
}


}else{
alert("请先选择Excel文件!");
return false;
}
  }


<input type="button" id="btn_imp" accesskey="d" onClick="importExcel()"
class="bottom" value="导 入">

<form action="upload.jsp?method=read" name="form1" id="form1" enctype="multipart/form-data" method="post" target="hidden_frame1">
<input type="file" id="filepath" name="filepath" style="display:none;width: 300" />
<iframe name='hidden_frame1' id="hidden_frame1"
style='display: none'></iframe>
</form>

------解决方案--------------------------------------------------------
alert(document.form1.submit());
这行注释掉吧
------解决方案--------------------------------------------------------
var name=aa.substring(aa.lastIndexOf("\\")+1); //截取名字

var name=filePath.substring(filePath.lastIndexOf("\\")+1);
这是一个问题

另外你的操作方式是的file组件中并没有选中的值,所以在multipart/form-data的提交的时候会拒绝提交
------解决方案--------------------------------------------------------
我能想到的就这些,还不行的话就要找大牛了
------解决方案--------------------------------------------------------
alert(document.form1.submit());
document.form1.submit();
相当于alert这一行已经提交了,下面一行就没有作用了 ,删掉一行
  相关解决方案