0

When this ajax call is executed and hits the server-side everything works as it is expected, but the problem is that no error or success is returned. In other words neither the success or the error is triggered in the ajax call definition.

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);
            }
        });

    }

Controller

  @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();
  }
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Noris
  • 157
  • 1
  • 6
  • Why are you redirecting the ajax request to an URL which returns a whole HTML page instead of returning a normal JSON response as apparently expected by JavaScript (if necessary with an instruction that JavaScript should perform a redirect to the given URL using `window.location`)? Where exactly have you learned this approach? This could never work that way. See also e.g. http://stackoverflow.com/q/4112686 – BalusC Jun 22 '16 at 08:43
  • will the redirection with window.location transfer the attributes that i have set in the controller ? @BalusC – Noris Jun 22 '16 at 10:40
  • you can store the json data in some variable or jquery session object before redirecting and use the same after redirecting. – SiddP Jun 22 '16 at 10:43

0 Answers0