首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在IE中修复我的jQuery代码?在Firefox中工作

如何在IE中修复我的jQuery代码?在Firefox中工作
EN

Stack Overflow用户
提问于 2010-03-20 15:17:08
回答 3查看 473关注 0票数 0

我使用jQuery来显示/隐藏一个div容器(#pluginOptionsContainer),并在其中加载一个页面(./pluginoptions.php)并发送所需的POST变量。

发送的POST数据基于选择列表的值(#pluginDD)和按钮的点击(#pluginOptionsBtn)……

它在Firefox中运行良好,但在IE中不起作用。在IE中,'$("#pluginOptionsContainer").load()‘请求似乎永远不会结束--我只会永远看到正在加载的消息...

bind()、empty()和append()在IE中似乎都工作得很好。而不是load()..

下面是我的代码:

代码语言:javascript
运行
复制
// 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!

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-03-20 15:40:56

IE有时会缓存响应。您可以通过观察IE向服务器发出的请求来进行检查。Fiddler2是一个很好的工具,用来监视http请求。

如果你注意到你点击了submit,但是没有看到任何http请求,IE会缓存结果。

如果是这样的话,你可以在url中添加一个随机数来缓存它:

代码语言:javascript
运行
复制
$("#pluginOptionsContainer").load("url.php?random=" + Math.random()*99999, dataString);
票数 3
EN

Stack Overflow用户

发布于 2010-03-20 15:45:42

当涉及到重复的元素ids时,IE有时比FF更挑剔。检查您使用的每个ID是否只使用一次,并且在ajax调用期间不会重新创建。

票数 0
EN

Stack Overflow用户

发布于 2010-03-20 16:13:56

如果缓存是问题所在,那么尝试在jquery的ajax设置中设置cache = false ...

代码语言:javascript
运行
复制
 $.ajaxSetup ({
        cache: false,
    });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2482276

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档