• <fieldset id="8imwq"><menu id="8imwq"></menu></fieldset>
  • <bdo id="8imwq"><input id="8imwq"></input></bdo>
    最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
    問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
    當前位置: 首頁 - 科技 - 知識百科 - 正文

    解決ajax提交到后臺數(shù)據(jù)成功但返回不走success而走的error問題

    來源:懂視網(wǎng) 責編:小采 時間:2020-11-27 22:51:29
    文檔

    解決ajax提交到后臺數(shù)據(jù)成功但返回不走success而走的error問題

    解決ajax提交到后臺數(shù)據(jù)成功但返回不走success而走的error問題:下面是ajax代碼和Controller層代碼,期初以為是后臺程序?qū)戝e了。 $(#sourcefile).ajaxSubmit({ type: post, dataType: json, // 'xml', 'script', or 'json' (expected server response type) url:
    推薦度:
    導讀解決ajax提交到后臺數(shù)據(jù)成功但返回不走success而走的error問題:下面是ajax代碼和Controller層代碼,期初以為是后臺程序?qū)戝e了。 $(#sourcefile).ajaxSubmit({ type: post, dataType: json, // 'xml', 'script', or 'json' (expected server response type) url:

    下面是ajax代碼和Controller層代碼,期初以為是后臺程序?qū)戝e了。

     $("#sourcefile").ajaxSubmit({ 
     type: "post", 
     dataType: "json", // 'xml', 'script', or 'json' (expected server response type) 
     url: "/springMVC/upload/up", 
     success: function (result) { 
     	 if (result) { 
     	 alert(result.col0);
     	 }
    	 	 
     }, 
     error:function(data, XMLHttpRequest, textStatus, errorThrown){ 
     	alert(1); 
     	 } 
     }); 
    
     @RequestMapping(value="/upload/up")
     
     public @ResponseBody ExcelName upload(@RequestParam("sourceFile") MultipartFile sourceFile, HttpServletRequest request, ModelMap model,HttpServletResponse response) { 
     	 //判斷文件是否為空
     if (sourceFile==null) return null;
     //獲取文件名
     String name=sourceFile.getOriginalFilename();
     System.out.println("name");
     //進一步判斷文件是否為空(即判斷其大小是否為0或其名稱是否為null)
     long size =sourceFile.getSize();
     if (name==null ||("").equals(name) && size==0) return null;
     
     //批量導入。參數(shù):文件名,文件。
     List<ExcelName> cpolicyList = ExcelUtils.batchImport(name,sourceFile);
     //迭代添加信息(注:實際上這里也可以直接將cpolicyList集合作為參數(shù),在Mybatis的相應映射文件中使用foreach標簽進行批量添加。)
     for( ExcelName customer:cpolicyList){
     	colDataService.insertData(customer);
     } 
     
     ExcelName e1=new ExcelName();
     e1.setCol0("success");
     return e1;
    }
    

    后打點跟蹤后臺發(fā)現(xiàn),原來因為上傳按鍵type寫成了submit導致提交了一次action,致使ajax未獲取到返回結(jié)果走了error。

    下面是修改正確后的jsp

    <%@ page language="java" contentType="text/html; charset=utf-8"
     pageEncoding="utf-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>上傳</title>
    <script type="text/javascript" src="./jquery-3.1.1.js"></script>
    <script type="text/javascript" src="./jquery.form.js"></script>
    <script type="text/javascript">
     
    function submitImport(){ 
     var epath = $('#source_file').val(); 
     
     if(epath==""){ 
     alert( '導入文件不能為空!'); 
     return; 
     } 
     
     if (epath.substring(epath.lastIndexOf(".") + 1).toLowerCase()!="xlsx") { 
     alert( '導入文件類型必須為excel!'); 
     return; 
     } 
     
     $("#sourcefile").ajaxSubmit({ 
     type: "post", 
     dataType: "json", // 'xml', 'script', or 'json' (expected server response type) 
     url: "/springMVC/upload/up", 
     success: function (result) { 
     	 if (result) { 
     	 alert(result.col0);
     	 }
    	 	 
     }, 
     error:function(data, XMLHttpRequest, textStatus, errorThrown){ 
     	alert(1); 
     	 } 
     }); 
    } 
    //partExport
    function downloadTemplate() { 
    	document.sourcefile.action = "/springMVC/upload/partExport";
     form.submit(); //表單提交
     }
     
     
    </script>
    </head>
    <body>
    <div>
     <form id="sourcefile" name="sourcefile" action="" method="post" enctype="multipart/form-data">
     <input type="button" value="添 加" onClick="addAirLine()" />
     <input style="margin-left: 20px;" id="source_file" name="sourceFile" type="file" value="選擇文件" />
     <input style="margin-left: 20px;" data-loading-text="請勿重復提交" type="button" value="上 傳" onClick="submitImport()">
     <input style="margin-left: 20px;" type="submit" value="下載模板" onClick="downloadTemplate();">
     </form>
     </div>
    </body>
    </html>
    

    以上這篇解決ajax提交到后臺數(shù)據(jù)成功但返回不走success而走的error問題就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

    聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

    文檔

    解決ajax提交到后臺數(shù)據(jù)成功但返回不走success而走的error問題

    解決ajax提交到后臺數(shù)據(jù)成功但返回不走success而走的error問題:下面是ajax代碼和Controller層代碼,期初以為是后臺程序?qū)戝e了。 $(#sourcefile).ajaxSubmit({ type: post, dataType: json, // 'xml', 'script', or 'json' (expected server response type) url:
    推薦度:
    • 熱門焦點

    最新推薦

    猜你喜歡

    熱門推薦

    專題
    Top
    主站蜘蛛池模板: 国产专区日韩精品欧美色| 少妇人妻偷人精品视频| 中文字幕九七精品乱码| 亚洲精品成人av在线| 精品无码久久久久久午夜| 日韩精品中文字幕第2页| 国产精品日韩深夜福利久久| 99久久99久久精品免费看蜜桃| 亚洲精品国产成人影院| 久久精品国产WWW456C0M| 99久久精品费精品国产| 国产大片91精品免费观看不卡| 久久99精品久久久久子伦| 亚洲av永久无码精品国产精品| 欧美精品一区二区久久| 国产精品综合专区中文字幕免费播放| 久久亚洲国产欧洲精品一| 成人国内精品久久久久影院| 精品无码人妻一区二区免费蜜桃| 亚洲国产成人精品无码区在线观看| 午夜一级日韩精品制服诱惑我们这边| 精品国产AⅤ一区二区三区4区| 国产精品国产三级在线专区 | 国产综合精品蜜芽| 99久久99久久精品国产片| 久久精品国产99国产精偷| 91精品国产高清91久久久久久| 久久夜色精品国产网站| 亚洲αv在线精品糸列| 亚洲精品成人网站在线观看| 在线精品国产一区二区三区| 亚洲精品乱码久久久久久中文字幕 | 97国产视频精品| 欧美精品亚洲精品日韩| 99re66热这里只有精品| 国产欧美日韩精品丝袜高跟鞋 | 999久久久国产精品| 9re热国产这里只有精品| 国产精品美女网站在线观看| 国产精品久久久99| 国产乱人伦精品一区二区在线观看|