jquery .load()不起作用

问题描述:

我似乎无法让jquery的.load()函数正常工作。必须是简单的东西我想念...基本上只是试图加载到index.html more.html的片段。jquery .load()不起作用

的index.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 

<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <script type="text/javascript" src="js/jquery-1.5.js" /> 
    <title>Test</title> 

    <script type="text/javascript"> 
     $(document).ready(function() { 
      alert("jquery script executing..."); 
      $('#foo').load('more.html #bar', loadComplete); 
     }); 

     function loadComplete (response, status, xhr) { 
      alert("load complete."); 
     } 
    </script> 
</head> 
<body> 
    <div id="foo"> 
     foo foo foo 
    </div> 
</body> 
</html> 

more.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>More</title> 
</head> 
<body> 
    <div id="bar"> 
     bar bar bar 
    </div> 
</body> 

我看到这两个警报 - 正在执行的脚本,回调正在称为(即负载正在完成)。但是,内容不会改变。我尝试过safari,chrome和firefox(全部在OSX上)。一定有什么明显的我想念...?

加载函数在jquery 1.5版本中被破坏。您可以在http://bugs.jquery.com/ticket/8125找到Bug票。这在1.5.1版中得到了修复。你可以找到最新的jquery版本,包含所有最新的修复,包括加载()在http://code.jquery.com/jquery-git.js

+0

aiaiaiai。那么这将解释它。尝试在jQuery论坛上发布相同的问题,但什么都没有。我知道*会给我爱。谢谢! – ericsoco 2011-02-27 19:45:18

+0

1.5.1已发布 – 2011-02-27 19:48:53

+0

1.5.1缩小形式Google CDN:https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js – dermatthias 2011-02-27 19:55:04