4
回答
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("<msg>"+states+"</msg>");
  
   response.getWriter().flush();
     
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }  
      
      return null;
 }

struts.xml :

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

在线急等!!!!!!!!!!!!!!

举报
吃花的鱼
发帖于6年前 4回/6K+阅
顶部