ajax和restfull架構使用

前端代碼 :

function answer() {

        var context = $("#gz_comment").val();//獲取頁面參數
        $.ajax({
            url : "http://localhost:8005/answer/"+id,//資源請求地址
            type : "post",
            data : {"context":context},
            dataType : "json",
            success : function(result) {
                if (result.code == 1) {
                    $(".text_1").val("");
                      window.location.reload();//刷新父窗口地址(頁面刷新)  
                }

            },
        });
    }  
 後臺代碼:

@RequestMapping(value="/answer/{id}",method=RequestMethod.POST) 

  public ResponseResult answer(String context,@PathVariable("id")int issueId){

       ResponseResult result = null;      

       try{           

                  result = questionService.addAnswer(context, issueId);   

    }catch(Exception e){   

        //返回結果      

     result = new ResponseResult();          

    result.setCode(2);         

  result.setMsg("提問失敗失敗");    

   }      

 return result;  

 }


發佈了29 篇原創文章 · 獲贊 8 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章