开发者

$.ajax working with Firefox, not IE

开发者 https://www.devze.com 2022-12-30 13:43 出处:网络
I have a jQuery code to allow users to login using a lightbox (http://colorpowered.com/colorbox/) and immediately start downloading files, without being redirected or having the page reloaded. It\'s p

I have a jQuery code to allow users to login using a lightbox (http://colorpowered.com/colorbox/) and immediately start downloading files, without being redirected or having the page reloaded. It's perfectly working in Firefox but Internet Explorer keeps showing the login box until I reload the page :(

<? if (!$this->session->userdata('user_logged_in')): ?>

<script type="text/javascript">
$(document).ready(function() {
    $('a[href^="/link/"]').click(function(event){
        var status = $.ajax({
            url: "/status",
            async: false
        }).responseText;
        if (status != 'USER_LOGGED_IN')
        {
            $.fn.colorbox({href:"/l开发者_StackOverflow社区ogin"});
            event.preventDefault();
        }
    });
});
</script>

<? endif ?>

Your help would be greatly appreciated.


The problem is that by default jQuery.ajax retrieves data using GET requests, which are being cached by IE. You can fix this by telling the browser to not cache AJAX results:

$.ajax({
        url: "/status",
        async: false,
        cache: false
    })


If the variable status is checked before it was set by the $.ajax part, it will keep sending you to the login screen. Try checking the status after it was successfully retrieved, like so:

$.ajax({
  url: '/status',
  async: false,
  success: function(status) {
    if (status != 'USER_LOGGED_IN') {
      // etc
    }
  }
});

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号