ajax向后台 controller傳遞參數


function saveReportData(fileName,fileID) {
    console.log("fileName="+fileName);
    $.ajax({
        type : 'post',
        url : '${ctx}/reportmanage/specialReportManage/saveReportData',
        data:{'srFileName':fileName,"srFileID":fileID},
        traditional : true,
        async : false,        
        success : function(result){
            
        },
        error : function(result){
        }
    });    
}

接收方式兩種

  •     說明:ajax的data參數名稱(紅色標識)必須和@RequestParam中的參數名稱保持一致
  • @RequestMapping(value = "saveReportData")
  •     @ResponseBody

      public String saveReportData(@RequestParam(value = "srFileName", defaultValue = "") String FileName,
              @RequestParam(value = "srFileID", defaultValue = "") String FileID) throws IOException {
          specialReportManageService.saveReportData(FileName, FileID);
          return "";
        }

  • 說明:如果沒有添加@RequestParam,函數的參數名稱必須和ajax中的參數名稱一致
  • public String saveReportData( String srFileName,String srFileID) throws IOException {

          specialReportManageService.saveReportData(FileName, FileID);
          return "";
        }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM