2016-10-08 13 views
0

私のコントローラにリクエストを投稿しようとしていますが、サブミットボタンを押すたびにリクエストが間違っています。 コードに何が問題なのかわかりません。Spring MVCでAjaxでBadRequestエラーが発生しました

home.jspを

<div id="setReminder"> 
        <label class="generalReminder" style="text-decoration: none;">General 
         Reminder</label> 
        <table> 
         <tr> 
          <td>Date</td> 
          <td><input type="text" readonly="readonly" 
           id="birthdayDate"></td> 
         </tr> 
         <tr> 
          <td>Time</td> 
          <td><input type="text" readonly="readonly" id="callTime" 
           ></td> 
         </tr> 
         <tr> 
          <td>Message</td> 
          <td><textarea id="reminderTag" rows="5"></textarea></td> 
         </tr> 
        </table> 
       </div> 
       <div id="reminderDot" style="margin-top: 24%; position: relative;"> 
        <button class="submitReminder" onclick="saveReminderDetails();">Submit</button> 
       </div> 

Home.js

function saveReminderDetails(){ 
var x=""; 
x=scheduleBirthdayReminder(); 
if(x){ 
    $.ajax({ 
     type:"POST", 
     url:"submitBirthdayRequest.do", 
     data : { 
      birthdayDate :$("#birthdayDate").val(), 
      birthdayTime : $("#callTime").val(), 
      birthdayReminder : $("#reminderTag").val() 
     }, 
     success : function(data) { 
      alert('data is'+data); 
      $("#birthdayDate").val(''); 
      $("#callTime").val(''); 
      $("#reminderTag").val(''); 
     } 
    }); 
} 

} 

Controller.java

@RequestMapping(value="submitBirthdayRequest.do",method=RequestMethod.POST) 
public @ResponseBody String submitSchedulerDetails(@RequestParam("birthdayDate")String birthdayDate,@RequestParam("callTime")String birthdayTime,@RequestParam("reminderTag")String reminderTag,HttpServletRequest request){ 
    System.out.println("adding reminder details with birthdayDate "+birthdayDate+"and time"+birthdayTime); 
    String userIdentity=((UserDetails)request.getSession(false).getAttribute("loginDetails")).getName(); 
    try{ 
     boolean schedulerObj= schedulerService.addSchedulerBirthdayDetails(userIdentity,birthdayDate, birthdayTime,reminderTag);  
    }catch(Exception e){ 
     e.printStackTrace(); 
    } 
    return birthdayTime; 

} 

エラー

http://localhost:8083/Testing/submitBirthdayRequest.do 400 (Bad Request) 

答えて

1

要求のパラメータの名前が期待どおりでない。

@RequestParam("birthdayTime") String birthdayTime 
@RequestParam("birthdayReminder") String reminderTag 

またはクライアント側たくさんありがとう

+0

上のparamの名前を変更を変更してみてください!!! 1 –

関連する問題