Ajax Success方法不更新html内容

时间:2015-01-07 14:30:00

标签: jquery html ajax

我的要求是调用ajax并且在成功或失败之后我必须向我的html添加文本消息.Ajax调用正在发生。响应也很好。但是没有更新html内容。

我的ajax电话:

$.ajax({      
    type:'GET',
    dataType: "json",
    url:'myurlhere',
    success: function(response){
           // errorHtml is updating here correctly
           var errorHtml = $('<div />').append(response[0]).html();
           $("#Error").html(errorHtml); 
    }, 
    error: function(e){
        var errorHtml = $('<div />').append('error').html();
        $('#Error').html(errorHtml); 
    }
}); 

我的HTML。这出现在表格中。

<td>
    <span  id="Error" style="alight:left">
</td>

注意:
1)我的回答是json list
2)我试过了

var errorHtml = '<div>'+response[0]+'</div>';

也。但它没有更新。

2 个答案:

答案 0 :(得分:0)

内容中不需要div包装,因为您已经在<span>内的<td>内。

假设response[0]确实包含有效数据,只需将内容直接放入错误范围:

$('#Error').html(response[0]);

请确保页面上只有一个ID Error的元素,当然......

答案 1 :(得分:0)

发现了这个问题。 之所以发生这种情况,是因为存在跨度的td是隐藏的。所以它正在更新js中的内容但是因为这个而没有更新html。谢谢你的回复。我有条件地隐藏了td.That是问题。当我搬家时它开始工作正常的其他部分的跨度。 希望这对其他人有帮助

相关问题