2012-03-23 31 views
0

在IE8中我收到了一個奇怪的行爲,數據沒有插入。在.html()中插入返回的數據ie7&ie8問題()

$.get('events.php', createEvents); 
    function createEvents(data) { 
    $('#result').html($(data)); 

,如果我嘗試

$('#result').append('<p>some html</p>'); 

這個工程但這並不

$('#result').append($(data)); 
+0

抱歉只編輯 – LeBlaireau 2012-03-23 10:46:12

+0

'console.log(data)'是你的朋友。你可能會得到你不希望的數據類型。 – ThiefMaster 2012-03-23 10:49:01

+0

ReferenceError:數據未定義 - 如何對此進行排序? – LeBlaireau 2012-03-23 10:51:42

回答

1

$.get()試圖確定響應的內容類型時要聰明。因爲你似乎總是得到HTML,使用$.ajax()有適當dataType選擇:

$.ajax({ 
    url: 'events.php', 
    method: 'GET', 
    dataType: 'html', 
    success: function(data) { 
     $('#result').html(data); 
    } 
}); 
+0

不行,奇怪 – LeBlaireau 2012-03-23 11:24:53

+0

然後你真的想看看你在回調函數中收到的數據... – ThiefMaster 2012-03-23 12:13:13

0

老式的innerHTML工作。其他瀏覽器都可以正常工作,所以我假設而不是你的代碼或數據是ie8的問題。可能是另一個小錯誤。