jQuery SerializeTable is a jquery plugin that get data from a table when clicked. And make into JSON all data, and can be read by PHP and return to fields or to any page by AJAX. View example
<script src="jquery.js"></script>
<script src="jquery.serializetable.js"></script>
<script>
$(document).ready(function() {
$('#your_table').serializeTable({
'file': 'path/to/file.php',
'params': 'parameter_name',
'data': '#element'
});
});
</script>
- file: Name of AJAX file. Defaults to
empty
. - params: Name of parameter to request. Defaults to
params
. - data: Element, ID or Class to return AJAX data. Defaults to
#content
. - attr: Attribute that contains the field name. Defaults to
rel
. - loading_text: Text displayed on loading. Defaults to
empty
. - loading_class: Class to personalize loading. Defaults to
serializetable-ldg
.
<script>
$(document).ready(function() {
$("#my_table").serializeTable({
"file": "ajax.php",
"params": "juice",
"data": "#return"
});
});
</script>
<table>
<thead>
<tr>
<th>Name</th>
<th>Color</th>
</tr>
</thead>
<tbody>
<tr>
<td rel="name">Heberti</td>
<td rel="color">Blue</td>
</tr>
<tr>
<td rel="name">Luis</td>
<td rel="color">Green</td>
</tr>
</tbody>
</table>
<div id="return"></div>
<?php
$json = $_REQUEST["juice"];
$obj = json_decode($json);
?>
<!-- Sample -->
<input type="text" value="<?php echo $obj[0]->name?>" />
<input type="text" value="<?php echo $obj[0]->color?>" />