<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>
<a href='two.php' class='ajax'>Two</a>
<div id="workspace">workspace</div>
one.php
$arr = array ( "workspace" => "One" );
echo json_encode( $arr );
$arr = array( 'workspace' => "Two" );
echo json_encode( $arr );
jQuery(document).ready(function(){
jQuery('.ajax').live('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]);
}
});
});
});
以上代码工作正常。当我单击链接“One”时,字符串“One”加载到workspace DIV中;当我单击链接“Two”时,字符串“Two”加载到workspace DIV中。
问题:
谢谢