我正在学习JSON和AJAX,需要有关本教程的帮助。
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
function makeTable(data){ // create table get data from database
var tbl_body = ""; // table body
$.each(data, function() { // table data
var tbl_row = "";
$.each(this, function(k , v) {
tbl_row += "<td>"+v+"</td>"; // table row
})
tbl_body += "<tr>"+tbl_row+"</tr>";
})
return tbl_body;
}
function getEmployeeFilterOptions(){ // get filter options value
var opts = [];
$checkboxes.each(function(){ // this function select when radiobutton is clicked
if(this.checked){
opts.push(this.value); // get check box values
}
});
return opts;
}
function updateEmployees(opts){ // update the filter value using ajax
$.ajax({
type: "POST", // POST method
url: "search.php", // search. page send data using json
dataType : 'json',
cache: false,
data: {filterOpts: opts},
success: function(records){
$('#employees tbody').html(makeTable(records));
}
});
}
var $checkboxes = $("input:radio"); // check radio button is clicked
$checkboxes.on("change", function(){
var opts = getEmployeeFilterOptions(); // update the database
updateEmployees(opts);
});
updateEmployees();
</script>
这里的结果(来自search.php
)显示在表格中,但我想要div中的所有数据。请帮我解决这个问题。