2013-04-16 97 views
0

我試圖更新一個div與$.get通話內容,但它是在ie(9).即不工作

js失敗的jQuery $不用彷徨是這個

function UpdateElementOfParent(box_id, page_ref, template_ref) 
{ 
$.get("get_content.php", { box_id: box_id, page_ref: page_ref, template_ref:template_ref }) 
    .done(function(data) {     
     $('#'+box_id).html(data);    
     }); 
} 

get_content.php是這

<?php 
include("connect.php"); 
$page_ref = $_GET['page_ref']; 
$template_ref = $_GET['template_ref']; 
$box_id = $_GET['box_id']; 
$sql = mysql_query("SELECT * FROM site_content WHERE page_ref='$page_ref' AND template_ref='$template_ref' AND box_id='$box_id' AND box_type='text'"); 
while($row=mysql_fetch_array($sql)) 
    { 
     echo stripslashes($row['content']); 
    } 
    ?> 

firefox/chrome/safari and opera.

工作正常

php的更新數據庫,但在iediv ("#"+box_id)犯規更新(只有ie9手頭所以不知道它只是9個或其它版本也)

任何線索?

快速更新

似乎即是從緩存中先前的$不用彷徨呼叫保持一些數據。基本上我在屏幕上有一個div,當用戶點擊一個按鈕時,一個圖層打開,並帶有可用nicedit編輯的textarea。 textarea填充了一個$ .get,然後用戶單擊保存,圖層被隱藏,並且父頁面上的原始div使用相同的$ .get調用進行更新。

在即,如果我更改內容,數據庫更新但div不是,當我打開圖層時,它仍顯示舊數據。

第一$不用彷徨調用這個

$.get("get_content.php", { box_id: box_id, page_ref: page_ref, template_ref:template_ref }) 
    .done(function(data) {   
     document.getElementById("edit_content").value=data; 
     area1 = new nicEditor({fullPanel : true}).panelInstance("edit_content",{hasPanel : true});    
     }); 

的警報數據犯規顯示在IE更新的文本,它肯定的東西與$不用彷徨呼叫

+0

嘗試'去除;從行' 5和6 – silentw

+0

@silentw,這不應該有任何問題 –

+1

@SamuelLiew你沒有讀過,有時IE是越野車,因爲不必要的';'? [REF](http://mislav.uniqpath.com/2010/05/semicolons/) – silentw

回答

0

確定問題解決了,我知道這是非常明顯的事情。

原來的$不用彷徨函數調用內我必須設置的document.ready狀態

function get_edit_content(box_id,page_ref,template_ref) 
    { 
    $(document).ready(function() { <<<<<HERE 
     if(area1) {  
      area1.removeInstance('edit_content'); 
      area1 = null; 
      document.getElementById("edit_content").value="";   
     } 
     $.get("get_content.php", { box_id: box_id, page_ref: page_ref, template_ref:template_ref }) 
     .done(function(data) {  
      document.getElementById("edit_content").value=data;   
      document.getElementById("page_ref").value=page_ref; 
      document.getElementById("template_ref").value=template_ref;   
      document.getElementById("box_id").value = box_id;      
      area1 = new nicEditor({fullPanel : true}).panelInstance("edit_content",{hasPanel : true});    
     }); 
    }); 

}

感謝所有的輸入

0

做,這是不是一個回答,因爲問題不完整,但我需要發佈代碼評論以協助OP。

正如你所提到的PHP工作得很好,問題可能是IE不喜歡jQuery中的動態選擇器。請嘗試以下幾種選擇:

1)更改$('#'+box_id).html(data);到:

var id = '#'+box_id; 
$(id).html(data); 

2)嘗試登錄或警報-ING的元素出來,看看是否IE實際上得到的元素右:

var elem = $('#'+box_id); 
alert(elem); 
elem.html(data); 

這將顯示爲[HTMLDivElement]或類似的東西,如果元素在那裏。

3)如果一切都失敗了,看看這個香草JS是否在IE中工作,以驗證它不是一個jQuery選擇器問題。

var elem = document.getElementById(box_id); 
alert(elem); 
elem.innerHTML = data; 
0

我想出了問題。與選擇器無關,但是參數變量的範圍爲box_id

的功能更改爲:

function UpdateElementOfParent(box_id, page_ref, template_ref) { 

    myBox = box_id; 
    $.get("get_content.php", { box_id: box_id, page_ref: page_ref, template_ref:template_ref }) 
     .done(function(data) {     
      $('#'+myBox).html(data);    
     }); 
} 

說明:

Ajax回調函數沒有訪問本地變量UpdateElementOfParent

+0

不,不能解決我的問題 –

+0

嘗試其他帖子然後 –