call data without refresh
I am trying to do a small thing, any 1 help me,开发者_开发百科 I really appricciate... I have a drop down menu,I want when I select the value, it will call the related data, which I am access with php+mysql, I dont want to jump to other page and show
html
<select id="select1" size="1">
<option value="1">value 1</option>
</select>
jQuery
$(document).ready(function(){
$('#select1').change(function(){
var url;
if (this.value == 1) {
url = 'sample1.php'
} else if (this.value == 2) {
url = 'sample2.php'
} else {
url = 'sample3.php'
}
var data = {'id': this.value }
$.ajax({
method: 'get',
data: data,
url: url,
success: function(result){
alert(result);
}
});
});
})
php sample.php
<?php
if ($_GET['id']) {
// do some MySql stuff....
echo 'some result';
}
?>
something like that... ;)
精彩评论