在$ http angular js中获取未定义的值

时间:2017-06-05 10:56:56

标签: angularjs

AngularJS代码:

$http({
  method: 'POST',
  url: 'saveEntity?formType=CompanyEntityModel',
  data: $.param($scope.obj), // pass in data as strings
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  } // set the headers so angular passing info as form data (not request payload)
}).success(function(data, status, headers, config) {
  console.log("success");
  console.log(eval(data));
}).error(function(data, status, headers, config) {
  console.log("Error Occured");
  console.log(eval(data));
});

这是后端代码:

@RequestMapping(value="/saveEntity" , method=RequestMethod.POST)
public @ResponseBody String saveEntity(@RequestParam("formType") String 
formType,WebRequest request) throws Exception, 

 {
   String result1=MessageConstant.FAILURE_ADD_COMPANY;//variable 
   contains"failure"
try {
    pentaService.saveEntity(formType,request);
    result1=MessageConstant.SUCCESS_ADD_COMPANY;//variable contains 
  "success"
} catch (Exception e) {
    // TODO Auto-generated catch block

}
return result1;

}

成功数据我发送"成功"从服务器端,但我得到一个未定义的值+它击中网址,执行所有任务,但它进入错误功能...我不知道为什么?我怎么能解决这个问题。

0 个答案:

没有答案