Redirect to another page using AJAX

1

An AJAX function, which passed a list containing the id of the selected rows of a table and two values of type date that are the start date and the end date. Those values are the process in a view that I have developed with Django . I want that after I work with that data the final result, return it as a data context for the page where I'm going to redirect.

The problem is that I can not redirect unless in my function succes put window.location = response.url , and that way I can not pass a data context.

    
asked by Alain Alvarez Caignet 20.08.2018 в 20:48
source

1 answer

0

If you return the address from Django within a json

data = {
    'key': '0',
    'value': 'direccion',
}

And if the request is correct, you get the value of the url.

    $.ajax({ 
        type: 'GET', 
        url: 'url', 
        data: { }, 
        dataType: 'json',
        success: function (data) {
            var url = ""
            $.each(data, function(index, element) {
                    url = element.value
            });
            if(url != "")
              window.location = url
        }
    });

I hope I have helped you.

    
answered by 21.08.2018 в 10:40