在服务器端成功运行后,不会触发成功或错误

时间:2016-06-22 08:32:12

标签: ajax spring spring-mvc

当执行此ajax调用并且命中服务器端时,一切都按预期工作,但问题是没有返回错误或成功。换句话说,在ajax调用定义中都不会触发成功或错误。

的Ajax

        $.ajax({
            type: "POST",
            url: "programBuilder",
            data: formObjCreator(),
            contentType: "application/json; charset=utf-8",
            cache: false,
            processData: false,
            dataType: "json",
            beforeSend: function(xhr) {
                xhr.setRequestHeader(header, token);
            },
            success: function(data){
                    alert("asd")
                },
            failure: function(errMsg) {
                alert(errMsg);
            }
        });

    }

控制器

  @RequestMapping(method = RequestMethod.POST) private String doPost(@RequestBody final ProgramBuilderCommand command, BindingResult result, Model model,
                      RedirectAttributes redir){

        if(result.hasErrors()){
                 model.addAttribute("message",result.getAllErrors().get(0).getDefaultMessage());
                return VIEW;
        }

        long programID = commandPersistenceService.saveCommand(command);
        redir.addFlashAttribute("message", "Settings has been updated.");
        redir.addAttribute("eventID", command.getEventID());
        redir.addAttribute("programID", programID);
        return "redirect:" + URL + "?programID=" + programID + "&eventID=" + command.getEventID();
  }

0 个答案:

没有答案