简体   繁体   English

jQuery load()在IE8和7中不起作用

[英]jQuery load() doesn't work in IE8 & 7

I got this code running 我让这段代码运行

$j('#nav_menu-2 li li a').bind('click', function(e){ 
    //check when pagination link is clicked and stop its action.
    e.preventDefault();

    //get the href attribute
    var link = $j(this).attr('href');

    $j('#content').load(link + ' #content');
});

its working fine in chrome, ff, ie9 but the problems begin with ie8 and ie7. 它在chrome,ff,ie9中可以正常工作,但问题始于ie8和ie7。

I searched the web and tried this way 我在网上搜索并尝试了这种方式

$j('#content').load(link + '?' + Math.random()*99999 + ' #content');

but its still not working, the content just doesn't show. 但它仍然无法正常工作,只是内容没有显示。
this is the url to the site 这是网站的网址

just click the first blue box(arrow 1), and try to change the content the arrow 2 and arrow 3. 只需单击第一个蓝色框(箭头1),然后尝试更改箭头2和箭头3的内容。

在此处输入图片说明

This looks wrong: 这看起来是错误的:

$j('#content').load(link + '?' + Math.random()*99999 + ' #content');

Try this instead: 尝试以下方法:

$j('#content').load(link + '?' + (Math.random()*99999).toString());

And I'm not sure you need that random number, unless you're having problems with cache. 而且我不确定您是否需要该随机数,除非您在缓存方面遇到问题。

$j('#content').load(link);

Here's a solution with cache disabled that looks up #content in the response, for good measure (untested): 这是一个禁用缓存的解决方案,可以很好地(未经测试)在响应中查找#content

$j.ajax({
    url: link,
    cache: false,
    dataType: "html",
    success: function(data){
        $('#content').html($(data).find('#content').html());
    }
});

the problem was an extra unneeded </div> tag inside the html code. 问题是html代码中多余的</div>标记。 All the modern browsers was able to handle this, but apparently ie8 and 7 just got lost that mess. 所有现代的浏览器都能够处理此问题,但是显然ie8和7只是迷失了方向。

ajax requests are cached in IE8, so just a little magic of Ajax请求被缓存在IE8中,因此

$.ajaxSettings.cache = false; $ .ajaxSettings.cache = false;

before the using load function 在使用加载功能之前

http://zacster.blogspot.in/2008/10/jquery-ie7-load-url-problem.html http://zacster.blogspot.in/2008/10/jquery-ie7-load-url-problem.html

http://api.jquery.com/jQuery.ajax/ http://api.jquery.com/jQuery.ajax/

cache (default: true, false for dataType 'script' and 'jsonp') 缓存(默认:true,对于dataType'script'和'jsonp'为false)
Type: Boolean 类型:布尔
If set to false, it will force requested pages not to be cached by the browser. 如果设置为false,将强制浏览器不缓存请求的页面。 Note: Setting cache to false will only work correctly with HEAD and GET requests. 注意:将缓存设置为false只能与HEAD和GET请求一起正常使用。 It works by appending "_={timestamp}" to the GET parameters. 它通过在GET参数后附加“ _ = {timestamp}”来工作。 The parameter is not needed for other types of requests, except in IE8 when a POST is made to a URL that has already been requested by a GET. 其他类型的请求不需要该参数,但在IE8中,当GET对已经由GET请求的URL进行POST时,则不需要该参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM