最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery - redirect after ajax call - Stack Overflow

programmeradmin1浏览0评论

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

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

Share Improve this question asked Jun 21, 2010 at 12:41 Ian morganIan morgan 9454 gold badges11 silver badges15 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 16

Instead of:

window.location(data);

Use:

window.location = data;

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

for some reason, i tried

window.location = data;

without success, but when used

document.location.href = data;

it worked, you can consider this too

发布评论

评论列表(0)

  1. 暂无评论