我的AJAX不会运行SUCCESS函数,但会执行我的控制器JAVA

时间:2018-08-09 01:39:41

标签: java ajax spring spring-mvc jsp

我试图执行我的控制器并获取用于警报消息的返回字符串,但是我的成功功能将无法正常工作。它执行控制器,但不执行成功功能。错误执行,但不显示任何消息。 下面是AJAX

var jsonData = {
				"appIDHidden": appname,
				"txtypeHidden": txtype,
				"ipaddress": ipaddress
			};
			$.ajax({
			  type: 'POST',
			  url: "checkaccesspermission",
			  data: jsonData,
			  dataType: 'json',
			  success: function(data) {
					if(data != "exists"){
						alert('Permission Already Exists!');
						return false;
					}else{
						alert('Add Permission test Succesful!');
						return true;	
					}
					alert('test123');
				},
				error: function(jqXHR, textStatus, thrownError)
				{
					alert(thrownError+jsonData[1]);
				},
			  async: false
			});
下面是控制器

 @RequestMapping(value="/checkaccesspermission", method=RequestMethod.POST)
    public String checkaccesspermission(@ModelAttribute("loginForm") IpAccessManagementModel loginForm, Model model,
            HttpSession session, BindingResult result,HttpServletRequest request,
            @RequestParam("ipaddress") String ipaddress,
            @RequestParam("txtypeHidden") String txtype,
            @RequestParam("appIDHidden") String appID) throws IOException{
            System.out.println("CHECKACCESSPERMISSIONs");
            IpAccessManagementModel sub = new IpAccessManagementModel();
            sub.setAppName(appID);
            sub.setTxtType(txtype);
            sub.setIpAddress(ipaddress);
            System.out.println(ipaddress);
            ipAccessMGTDAO.addPermission(sub);
            String resultCheckExist = ipAccessMGTDAO.checkAccessPermission(sub);
            System.out.println("checkResult:|"+resultCheckExist+"|");
            return resultCheckExist;
    }

1 个答案:

答案 0 :(得分:1)

没关系,我通过在控制器上添加@public ResponseBody使其起作用:@RequestMapping(value="/checkaccesspermission", method=RequestMethod.POST) public @ResponseBody String checkaccesspermission