Home > OS >  Redirect to another page with @RequestBody
Redirect to another page with @RequestBody

Time:12-04

I'm struggling with something.

i pass JSON data to my controller

$.ajax({
                type:'POST',                
                url:'${pageContext.request.contextPath}/saveMovBienes2',
                data:  JSON.stringify({ dni:dni, table:table, tipoMov:tipoMov}),
                dataType: "json",
                contentType: 'application/json'
            })

In my RestController, i handle this information like this

@PostMapping("/saveMovBienes2") 
    public String saveMovBienes2(@RequestBody Request myRequest)

saving the JSON elements into the object myRequest.

The thing is, having @RequestBody forces me to stay in that JSP, but i want to after processing this information, redirects to another page.

Tried with various ways to redirect but the view stays the same (in my console i see the info processing but the view is static)

I read people with the same problem, and their answer was "removing @RequestBody", but in my case i'm not able to make it work without the @RequestBody.

Is there any way to rediect? or i have to modify all my code?

CodePudding user response:

I finnally find a workaround, thanks to the comments above:

.done(function() {
        })
        .fail(function(){
            window.location = '${pageContext.request.contextPath}/nuevoMovimientoBU';
        })

For some reason, its not entering to .done , but in .fail

  • Related