2010-03-20 49 views
0

我正在使用jQuery顯示/隱藏div容器(#pluginOptionsContainer),並在其中加載頁面(./plugin_options.php),並使用所需的POST變量發送。如何解決我在IE中的jQuery代碼?在Firefox中工作

什麼POST數據是基於選擇列表(#pluginDD)和一個按鈕(#pluginOptionsBtn)的點擊的價值被送到...

它工作在Firefox罰款,但不工作在IE中,'$(「#pluginOptionsContainer」).load()'請求似乎永遠不會在IE中完成 - 我只能看到永久加載的消息...

bind(),empty()和append )似乎都在IE中很好地工作。但不加載()..

這裏是我的代碼:

// wait for the DOM to be loaded 
$(document).ready(function() { 

// hide the plugin options 
$('#pluginOptionsContainer').hide(); 

// This is the hack for IE 
if ($.browser.msie) { 
    $("#pluginDD").click(function() { 
    this.blur(); 
    this.focus(); 
    }); 
} 

// set the main function 
$(function() { 

    // the button shows hides the plugin options page (and its container) 
    $("#pluginOptionsBtn") .click(function() { 
    // show the container of the plugin options page 
    $('#pluginOptionsContainer').empty().append('<div style="text-align:center;width:99%;">Loading...</div>'); 
    $('#pluginOptionsContainer').toggle(); 
    }); 

    // set the loading message if user changes selection with either the dropdown or button 
    $("#pluginDD,#pluginOptionsBtn").bind('change', function() { 
    $('#pluginOptionsContainer').empty().append('<div style="text-align:center;width:99%;">Loading...</div>'); 
    }); 

    // then update the page when the plugin is changed when EITHER the plugin button or dropdown or clicked or changed 
    $("#pluginDD,#pluginOptionsBtn").bind('change click', function() { 
    // set form fields as vars in js 
    var pid = <?=$pid;?>; 
    var cid = <?=$contentid;?>; 
    var pDD = $("#pluginDD").val(); 
    // add post vars (must use JSON) to be sent into the js var 'dataString' 
    var dataString = {plugin_options: true, pageid: pid, contentid: cid, pluginDD: pDD }; 
    // include the plugin option page inside the container, with the required values already added into the query string 
    $("#pluginOptionsContainer").load("/admin/inc/edit/content/plugin_options.php#pluginTop", dataString); 
    // add this to stop page refresh 
    return false; 
    }); // end submit function 

}); // end main function 
}); // on DOM load 

任何幫助將非常感謝!我討厭IE瀏覽器!

回答

3

IE有時會緩存響應。您可以通過查看IE對服務器的請求進行檢查。 Fiddler2是一款非常適合觀看http請求的工具。

如果您發現您點擊了提交,並且沒有看到任何正在發起的http請求,IE會緩存結果。

如果是這樣的話,你可以隨機號碼添加到URL緩存胸圍它:

$("#pluginOptionsContainer").load("url.php?random=" + Math.random()*99999, dataString); 
+0

必須爲幾乎所有的jQuery的崗位做到這一點,很煩人,IE瀏覽器做到這一點。 – 2010-03-20 07:43:21

+0

@Tom Anderson:IE不緩存來自POST請求的響應,只有GET。 – 2010-03-20 08:30:49

+0

現在,它的工作原理...我之前嘗試過,使用一種稍微不同的生髮隨機數的方法,它不工作..但他的一個!非常感謝!!該死的你IE! – sc0ttman 2010-03-20 08:41:22

0

IE有時是挑剔那麼FF,當涉及到重複的元素的ID。 檢查您使用的每個ID是否僅使用過一次,並且不會在ajax調用期間重新創建。

+0

是的,我注意到,一段時間後,這是一個真正的屁股疼痛! – sc0ttman 2010-03-20 08:45:22

0

如果緩存的問題,然後嘗試設置緩存= jQuery中的Ajax設置假...

$.ajaxSetup ({ 
     cache: false, 
    }); 
+0

我這樣做,沒有效果......但jrallison提供了工作解決方案..無論如何。 – sc0ttman 2010-03-20 08:46:00

相關問題