IE img load返回错误

时间:2013-02-05 14:38:47

标签: javascript jquery internet-explorer

我正在尝试从ajax repsonse插入图像。 一切正常,但不在IE中。

我尝试过:Image load not working with IE 8 or lower,但获得了“破碎的形象”。

试图解决这里描述的问题:http://www.paulund.co.uk/handle-image-loading-errors-with-jquery,但它没有解决任何问题。我没有将它附加到document.ready函数,因为这是ajax,IE< ajax调用永远不会触发9 hack。通过鼠标单击触发Ajax调用,该鼠标单击具有图像链接。使用JQuery的对话框功能时,IE不会显示图像。通过右键单击并“显示图像”强制显示图像。

有谁知道如何解决这个问题?

function search(url){
$.ajax({
      type: "GET",
      url: url,
      dataType: "html",
      success: function(data, status, XMLHttpResponse){
            clickListenerEvent();
        },
      error: function(data, textStatus, XMLHttpResponse){
            alert("AJAX error");
        }
    });
}

function clickListenerEvent(){
$('a.show-image').click(function (e) {
    var element = $(this);
    var href = element.attr('href');
    var title = element.attr('title');

    var thisId = 'dialogbox_'; 

    var exisitingDialog = $('.dialogbox[id='+thisId+']');
    if(!exisitingDialog.length){
        element.parent().append("<div id='"+thisId+"'></div>");
    }
    var thisDialog = $('.dialogbox[id='+thisId+']');

    var img = new Image();
    $(img).load(function() {
        alert('successfully loaded');
    }).error(function() {
        alert('broken image!');
        //$(this).attr('src', href);
    }).attr('src', href);

    $(thisDialog).append(img);

    //create the dialog
    $('.dialogboks[id='+thisId+']').dialog({
        closeText: 'Close',
        title: title
    });


    if ( $.browser.msie && $.browser.version < 9 ) {
        $('img').each(function(){
            $(this).attr('src', $(this).attr('src'));
        });
    }

    e.preventDefault();
    });
}

0 个答案:

没有答案
相关问题