1

我使用ajax将一些数据传到我的页面,并使用.html()更改div的html内容。 一切工作正常在Firefox,谷歌铬,Safari浏览器,歌剧除了INTERNET EXPLORER。.html()不能在Internet Explorer中工作

IE 7,8,9无法响应.html()函数,该div的内容保持不变。

这里是我的代码:

var userurl = $('#userthumb a').attr('href'); 
$(document).ready(function(){ 
    $('#userthumb').after("<div id='to-change'>Loading...</div>"); 
     $.ajax({ 
      type: "GET", 
      url: "parse.php", 
      data: "url=" + userurl, 
      dataType: 'json', 
      cache: false, 
      success: function(data) 
      { 
       var respond = data['respond'];  
        $('#to-change').html(respond + 'profile'); 
      } //end of success 
      }); //end of ajax 
}); 

有任何问题或者是有解决IE问题的方法吗?

+0

返回的HTML是什么样的?缺少标签会对IE造成严重破坏。 –

+0

重复与http://stackoverflow.com/questions/412734/jquery-html-attribute-not-working-in-ie – ComfortablyNumb

+0

只是一个JSON {“respond”:“用户名”} – sm21guy

回答

0

这可能解决这个问题:

success: function(data) { 
    eval('var jSON = '+data); 
    $('#to-change').html(jSON['respond'] + 'profile'); 
} //end of success 

编辑: 确保您返回的数据格式,例如:

{'respond':'it worked as expected','.....':'....'} 

在我的VB脚本我回:

。​​

然后,

eval('var jSON='+data); 
if (jSON['Success'] == 'MoveOn') ....... 
+2

Eval?不,谢谢... – JCOC611

+0

它返回元素列表“var jSON = [Object object]; – sm21guy

+0

所以我们需要两个对象 – sm21guy

0

尝试

$('#to-change').html($.parseJSON(data).respond + 'profile'); 
+0

$ .parseJSON(数据)为空? – sm21guy

0

试试这个: $( '#到变化')空()追加(应对+ '个人资料');

相关问题