我的index.php是这样的:
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript" src="ajax.js"></script>
<a href='one.php' class='ajax'>One</a>
<div id="workspace">workspace</div>
one.php
<?php
$arr = array ( "workspace" => "<a href='two.php' class='ajax'>two</a>" );
echo json_encode($arr);
?>
two.php
<?php
$arr = array( 'workspace' => "Hello World" );
echo json_encode($arr);
?>
ajax.js
jQuery(document).ready(function(){
jQuery('.ajax').click(function(event) {
event.preventDefault();
// load the href attribute of the link that was clicked
jQuery.getJSON(this.href, function(snippets) {
for(var id in snippets) {
// updated to deal with any type of HTML
jQuery('#' + id).html(snippets[id]);
}
});
});
});
当的index.php被加载,有一个链路(上)和一个DIV(工作区)。当我点击一链接,然后one.php的内容被称为和纽带两课成功地出现在工作区股利。
When index.php is loaded, there is a link(One) and a DIV(workspace). When I click 'One' link then content of one.php is called and link 'Two' appeared in 'workspace' DIV successfully.
但现在,当我点击链接两课然后'你好世界'并没有出现在工作区DIV,并分别打开,而AJAX调用。
But now when I click link 'Two' then 'Hello World' does not appear in 'workspace' DIV and opened separately without AJAX call.
如何强制该code来代替工作区DIV与'你好世界'使用上述流链接两节的内容?
感谢
推荐答案
尝试 生活()
方法,而不是点击
:
jQuery('.ajax').live('click', function(event) {
// your code
});
在生活
时使用该内容已分配的事件或者是present或添加/后加载。
The live
is used when the content you have assigned events to is either present or is added/loaded later.