Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - redirect after ajax call

I have the following code, however im having a problem getting window.location to work

$('.test_container a').click(function() {

    $.ajax({
            url: $(link).attr('href'),
            type: 'GET',
            dataType: 'json',
            beforeSend: function() {
                $('#lightbox').show();
            },
            success: function(data) {
                $('#lightbox').hide();

                window.location(data);
            }
        });


    return false;
});

If window.location.replace is used instead it does work, however this then doesnt allow the brwser back buttons to work.

Does anyone know of any solution?

Thanks

like image 219
Ian morgan Avatar asked Jun 21 '10 12:06

Ian morgan


1 Answers

Instead of:

window.location(data);

Use:

window.location = data;

The location is a property of the window object not a method.

like image 180
Sarfraz Avatar answered Oct 21 '22 19:10

Sarfraz