我的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)。