Search code examples
jqueryajaxinternet-explorer-7internet-explorer-6

jQuery .ajax method in IE7 & IE6 not working but working fine in Firefox


This relates to my previous post:

jQuery .load Method causing page refresh AJAX

I changed my implmentation to use the .ajax method instead of .load and it works fine in Firefox but not in IE7 or IE6:

    $('ul#coverTabs > li > a').live('click', function(event) {

    // Find href of current tab
    var $tabValue = $(this).attr('href');

    $.ajax({
        type: "GET",
        cache: false,
        dataType: "html",
        url: $(this).attr('href'),
        success: function(data){

        $(data).find('.benefitWrap').each(function(){

            var $benefitWrap = $(this).html();

            $('.benefitWrap').replaceWith($('<div class="benefitWrap">' + $benefitWrap + '</div>'));

        });

       }

    });

    event.preventDefault(); 

});

This is killing me as it has taken ages to get this far.

Any ideas where i am going wrong?


Solution

  • I accidentally worked out what the issue was.

    The link referenced in this variable:

    var $tabValue = $(this).attr('href');
    

    Had a hash value on the end like so:

    https://bupacouk.bwa.local.internal.bupa.co.uk/cash-plan-quote/quoteAction.do?getBenefitLevelDetails=getBenefitLevelDetails&productPolicyId=7850#a1
    

    This cause the AJAX to fall over in bothe versions of IE.

    Using the following code:

    var $withoutHash = $tabValue.substr(0,$tabValue.indexOf('#'));
    

    Getrs rid of it and it now works :)