开发者

jQuery.ajax not working in IE7/8

Something in my script is breaking IE.

I'm looking on a collection of links with a class, and hijacking the URL's. Clicking a link will animate the height and reveal a message. It also does an ajax request to mark the message as read.

However, in IE it simply goes to the URL instead of staying on the page and processing the http request.

$('.message .subje开发者_JS百科ct .subject_link').click(function(e) {

    toggle_message(e)
    return false;

});


function toggle_message(m) {

var link = m.target;
var parent = $(link).parent().parent();
console.log(link.href);
$.ajaxSetup({

    url: link.href,
    dataType: 'json',
    timeout: 63000,
    type: 'GET',
    cache: false

});

if($(parent).hasClass('unread')) {

    $(parent).addClass('read').removeClass('unread');

    $.ajax({

        complete: function(r, textStatus) {
            console.log(r.responseText)
        }

    });

}

if($(parent).find('.body_wrapper').hasClass('collapsed')) {
    $(parent).find('.body_wrapper').addClass('expanded').removeClass('collapsed');
    $(parent).find('.body_wrapper').animate({
            height: 'toggle'
    })
} else {
    $(parent).find('.body_wrapper').addClass('collapsed').removeClass('expanded');
    $(parent).find('.body_wrapper').animate({
            height: 'toggle'
    }) 
}

}

any ideas what's causing this issue? http://support.cooper.krd-design.net/ tester: 12345 if you want to review the page

Thanks Rich


Adding

e.preventDefault();

before toggle_message in the first function should work, although return false should as well.


I don't have access to IE right now but I think you could try preventing the default click event to fire in your click()-function like so:

$('.message .subject .subject_link').click(function(e) {
    toggle_message(e)
    e.preventDefault();
});

More on .preventDefault() here: http://api.jquery.com/event.preventDefault/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜