从Spring控制器返回正确的响应,但控制权转至Ajax错误406:不可接受

时间:2019-07-03 02:51:46

标签: javascript java jquery ajax

我的ajax调用看起来像这样

function getInfo(pNum){
        //AJAX Start            
        $.ajax({  
         type: "GET", 
               contentType : "application/json",
         url: "getPInfo.do",  
         data: "&pNum=" + pNum,
         dataType : 'json',
         async: false,
        success: function(response){
        alert(response);
        if(response !== null || response !== ''){   
                        var JSONresponse = JSON.parse(response);
                        var a = JSONresponse.status;    
                        alert(a);
                 }},  
                 error: function(e){                    
                    alert("Error..."+e);
                 } 
        });


    }

控制器代码如下

@SuppressWarnings("unchecked")
    @RequestMapping(value = "/getPInfo.do", method = RequestMethod.GET)
    public @ResponseBody JsonResponse getPInfo(@RequestParam("pNum") Long pNum, HttpSession session, HttpServletRequest request ) { 
        JsonResponse  result = new JsonResponse();

        try {

                Perm  perm = new Perm();
                perm = pService.getPInfo(pNum);

                if(perm != null){
                    result.setStatus("SUCCESS");                    
                    result.setResult(perm);
                }
        } 
        catch (Exception e) {
            System.out.println("Exception ", e);
        }  

        return result;

    }

这是我的JsonResponse类。

public class JsonResponse {

    private String status = null;  
    private Object result = null;


    public String getStatus() {
        return status;
    }
    public void setStatus(String status) {
        this.status = status;
    }
    public Object getResult() {
        return result;
    }
    public void setResult(Object result) {
        this.result = result;
    }   


}

当我尝试打印烫发时,所有对象均已正确设置。但是ajax返回到  错误:功能(e)。

0 个答案:

没有答案