Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从IE9中的ajax调用使用html更新div_Javascript_Jquery_Internet Explorer 9_Innerhtml - Fatal编程技术网

Javascript 从IE9中的ajax调用使用html更新div

Javascript 从IE9中的ajax调用使用html更新div,javascript,jquery,internet-explorer-9,innerhtml,Javascript,Jquery,Internet Explorer 9,Innerhtml,我试图将ajax调用中的数据添加到页面上的div中。以下内容在webkit浏览器中运行良好,但在IE中失败- $.ajax({ type: 'POST', url: '/cart/add_to_cart', data: {'item_id': item_id}, success: function(data) { $('#cart_summary').html(data); } )}; 我的html如下所示: <div id="ca

我试图将ajax调用中的数据添加到页面上的div中。以下内容在webkit浏览器中运行良好,但在IE中失败-

$.ajax({
    type: 'POST',
    url: '/cart/add_to_cart',
    data: {'item_id': item_id},
    success: function(data) {
        $('#cart_summary').html(data);
    }
)};
我的html如下所示:

<div id="cart_summary">
    <a class='link_to_cart' href="/cart/">
        <span> CART &#40;5&#41; &pound;1054.75 </span>
        <img id="cart_icon" src="/static/images/cart_icon.tiff">
    </a>
</div>
但这也失败了(在IE调试器中查看cartSummary.innerHTML的结果会显示我想要的html,但它不会显示在页面上)

我还尝试了jQuery的
.remove()
.text()和
.append()
的各种组合,但都没有效果。

这可能会有帮助:

jQuery Ajax错误处理功能

$(function() {
    $.ajaxSetup({
        error: function(jqXHR, exception) {
            if (jqXHR.status === 0) {
                alert('Not connect.\n Verify Network.');
            } else if (jqXHR.status == 404) {
                alert('Requested page not found. [404]');
            } else if (jqXHR.status == 500) {
                alert('Internal Server Error [500].');
            } else if (exception === 'parsererror') {
                alert('Requested JSON parse failed.');
            } else if (exception === 'timeout') {
                alert('Time out error.');
            } else if (exception === 'abort') {
                alert('Ajax request aborted.');
            } else {
                alert('Uncaught Error.\n' + jqXHR.responseText);
            }
        }
    });
});

添加后,调用ajax函数,您将获得错误详细信息

好的,我找到问题了。我编写了一个狡猾的django模板标记,它抛出了一个未关闭的
标记。Internet explorer处理这个(非常)奇怪,并且把dom弄得一团糟

这样做的结果是我有两个
元素(仅在IE上-我从未找出原因)。可以想象,这给
document.getElementById('cart\u summary')
$('cart\u summary')
带来了问题

解决方案是删除重复的元素id


(非常感谢Palash Mondal、rcdmk、Explosion Pills、Webweaver和Wirey花时间调查我的问题)。

控制台中是否显示了某种错误?不,控制台中没有任何内容。你有指向该页面的链接吗?我在问题的主体中添加了一个链接(我有点偏执,所以我真的不希望我的开发服务器的链接在互联网上浮动-我可以从我的问题中删除链接,但不能删除我的评论)@AidanEwen尝试在你的代码中添加这个
$.ajaxSetup({cache:false})
-IE在缓存方面有问题,通常将ajax调用的缓存设置为false会解决这个问题,谢谢,但我的ajax调用不是问题所在。(查看我的数据变量可以确认这一点)。尝试将
控制台.log(data);
放入success func()中。值是什么样的?是json、string还是int?它是一个字符串-我的代码在webkit浏览器中运行良好。这只是IE。我在IE9开发工具中调试了JS,在错误回调中设置了一个断点,给了我errorThrown=“禁止”。我还看到此调用中使用的令牌变量为null。
$(function() {
    $.ajaxSetup({
        error: function(jqXHR, exception) {
            if (jqXHR.status === 0) {
                alert('Not connect.\n Verify Network.');
            } else if (jqXHR.status == 404) {
                alert('Requested page not found. [404]');
            } else if (jqXHR.status == 500) {
                alert('Internal Server Error [500].');
            } else if (exception === 'parsererror') {
                alert('Requested JSON parse failed.');
            } else if (exception === 'timeout') {
                alert('Time out error.');
            } else if (exception === 'abort') {
                alert('Ajax request aborted.');
            } else {
                alert('Uncaught Error.\n' + jqXHR.responseText);
            }
        }
    });
});