現在ajaxで受け取ったデータをコントローラーに飛ばして、そこからjspにデータを渡して遷移するプログラムを書いていますが、postでしかデータが表示できません。
lang
1function otheruser(user_id){ 2 3 $.ajax({ 4 url:'otheruser', 5 data:{ 6 userId : user_id 7 }, 8 type : 'post', 9 cache : false, 10 success : function(data){ 11 if(data){ 12 //コントローラーに送信 13 window.location.href ="otheruser"; 14 }else{ 15 //送信エラー 16 alert("失敗"); 17 } 18 } 19 }); 20 21}
lang
1 @RequestMapping(value = "/otheruser", method = RequestMethod.GET) 2 public String OtherUser(Model model,HttpSession session) { 3 return "otheruser"; 4 } 5 6 @RequestMapping(value = "/otheruser", method = RequestMethod.POST) 7 public String OtherUser1(Model model,@RequestParam int userId,HttpSession session) { 8 9 10 //ログインユーザーデータ取得(名前、情報など 11 user_entity userInfo = tweetservice.userInfo(userId); 12 13 //ユーザデータをモデルでmypageに送信 14 model.addAttribute("userData",userInfo); 15 16 System.out.println(userId); 17 return "otheruser"; 18 } 19
@RequestParam int userIdでユーザIDを受け取っていますが、GETだと受け取れません。なぜならGETでuserIdを受け取ると400エラーが発生してしまうので、現在はこの形になっていますがこれだとjspでページを表示したときにIdが受け取れないので、何もできません。
何かいい方法があれば教えていただければと思います。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/11/08 23:35