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>
<a href='two.php' class='ajax'>Two</a>
<div id="workspace">workspace</div>
one.php
$arr = array ( "workspace" => "One" );
echo json_encode( $arr );
two.php
$arr = array( 'workspace' => "Two" );
echo json_encode( $arr );
ajax.js
jQuery(document).ready(function(){
jQuery('.ajax').live('click', function(event) {
event.preventDefault();
jQuery.getJSON(this.href, function(snippets) {
for(var id in snippets) {
jQuery('#' + id).html(snippets[id]);
}
});
});
});
It works fine on code. When I click the One link, then the One line is loaded into the DIV workspace, and when I click the Two link, then the Two line is loaded into the DIV workspace.
Question:
Now I want to use the drop-down list to load one.php and two.php into the DIV workspace instead of the links in index.php. When I use a link, I use class = 'ajax' in the link properties, but how do I call an ajax request when a change event changes?
thank
source
share