开发者社区> 问答> 正文

jQuery 回调函数不执行

我用jQuery的插件jquery.form.js 做一个文件上传的操作 后台struts2接受 返回xml 数据 但是我的jQuery回调函数不执行 以下是我的代码 希望各位大虾指点一下

html :

<%@ page language="java" contentType="text/html; charset=GB2312"%>   
<%@ taglib prefix="s" uri="/struts-tags" %>  
<html>
     <head>
      <script type="text/javascript" src="js/jquery.form.js"></script> 
       <script type="text/javascript" src="js/jquery.js"></script> 
        
     <script type="text/javascript">
      
      function ajaxAddSubmit(){
       // var data = document.getElementById("form1");
         
         var options = {
      url:'doUpload',
      dataType: 'text/xml',
     // data:{func:functemp,lan:cutlink2('lan')},
      error: function(){
         alert("oooo");
       },
      success: function(data) {
        alert("000");
      }};
     $('#form1').ajaxSubmit(options); 
         
       } 
       
      </script>
     </head>
 <body>
  
  <s:form name="form" id="form1" action="doTxtUpload" method="POST" enctype="multipart/form-data"  >
 
 添加TXT作品:<input type=file name="upload" style="width:300px;height:20px;" value="浏览"/>
 <input type=radio name="states" value="0" checked=true/>传至草稿箱 
 <input type=radio name="states" value="1"/>提交审核 &nbsp;&nbsp;
 <input type="submit" value="上传" onclick="submitForm();" style="width:70px;height:20px;"/>
 
 
</s:form>
</body>
</html>

action:

public String execute(){
/*/
HttpServletResponse response = ServletActionContext.getResponse();

System.out.println(states);

response.setContentType("text/xml;charset=utf-8"); //会乱码

 response.setCharacterEncoding("UTF-8"); //(

 response.setHeader("Cache-Control", "no-cache");   
 try {

PrintWriter out=response.getWriter();

  System.out.println("aaaaaaaaaaaaa");

   

out.print(""+states+"");

response.getWriter().flush();

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

   
  return null;

}
struts.xml :

<package name="action" namespace="/" extends="struts-default">
<action name="doTxtUpload" class="com.LoginAction">
    
</action>    
</package>

展开
收起
a123456678 2016-07-08 14:36:00 2128 0
1 条回答
写回答
取消 提交回答
  • submitForm()这个JS方法在哪儿,怎么没看到呢?

    还有,type="submit"点击之后默认就有提交form(

    至于你按我说的做了,可能还是弄不起,那可能还有其它问题,不过先把我上面说的问题解决了来。

    2019-07-17 19:53:23
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关课程

更多

相关电子书

更多
Javascript中的函数 立即下载
JavaScript函数 立即下载
JavaScript异步编程 立即下载