Internet Explorer freezing in a function call

Discussion in 'JavaScript' started by mts7, Jul 5, 2011.

  1. #1
    I have a JavaScript function that works in other browsers, but not IE 7 or 8. The problem seems to be the line below.

    var td_id = $('td[onclick*="\''+tsku+'"]').attr('id');

    Using Firebug Lite in Internet Explorer 8, I can run that line of code, and get the expected value. When I run customize(), IE freezes, getting my CPU usage up to 100%. What ideas do you have for getting IE 8 to work with this function?

    I updated jQuery to 1.6.1, and that had no apparent effect on this issue.

    Tested Browsers:
    Firefox 3-5
    Chrome
    Safari 5 (Win)
    Opera 11 (Win and Android)
    Internet Explorer 9


    
    function customize(sku) {
        $.ajax({
            type: 'POST', 
            url: '/api.php',
            dataType: 'text',
            data: {
                action: 'get_contents',
                sku: sku
            },
            async: false, 
            success: function(data, msg){
                // data should be a CSV string
                if (is_string(data)) {
                    var skus = data.split(',');
                    for (var key in skus) {
                        var tsku = skus[key];
                        var td_id = $('td[onclick*="\''+tsku+'"]').attr('id');
                        if (td_id) {
                            var subject = td_id.replace(/_title.+$/, '');
                            var id = td_id.replace(subject+'_title_', '');
                            var selector = 'table_row_'+subject+'_'+id;
                            select_product(tsku, subject, id, selector);
                        } else {
                            td_id = $('a[href*="'+tsku+'"]').parent().parent().attr('id');
                            if (td_id) {
                                var id = td_id.replace(/[a-zA-Z_]+/, '');
                                addToBasket(id, 'Additional', td_id);
                            }
                        }
                    }
                }
            }
        });
    }
    
    PHP:
    Any help is greatly appreciated.

    MTS
     
    mts7, Jul 5, 2011 IP
  2. mts7

    mts7 Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I removed the \' from the line, and IE isn't having issues anymore. It was originally there to find '+SKU within an onclick attribute. The script seems to be working without that part, so I suppose IE just doesn't like having a \' in the code (without a closing one).
     
    mts7, Jul 6, 2011 IP