我有一个选择选项,我选择一个,我想从数据库中更改tablo值。 在我的观点中:
<select id="Room" >
<option value="Joseph">Joseph Room</option>
<option value="Macro">Macro Lounge</option>
</select>
<table>
<tr>
<td>Day</td>
<?php
foreach ($posts as $post)
{
echo "<td>{$post->seancehour}</td>";
}
?>
</tr>
<tr>
<td><?php echo $post->seanceday; ?></td><td><?php echo $post->seancename; ?></td>
</tr>
</table>
我使用ajax并想要更改dynamiccally表值。我的javascript是:
<script type="text/javascript">
$(document).ready(function () {
$('#Room').change(function () {
var room = document.getElementById("Room").value;
$.ajax({
type: 'POST',
data: {room: room},
url: '<?php echo site_url('Homepage/index'); ?>',
success: function (result) {
alert(result);//I dont know what has to be here.
}
});
});
});
</script>
在我的Controller中,我转到mymodel并获取数据库值。
public function index()
{
$room = $this->input->post('room');
if ($room == 'Macro')
{
$this->data['pasts'] = $this->SeanceModel->getMacro();
}
else
{
$this->data['posts'] = $this->SeanceModel->getJoseph();
}
$this->load->view('Homepage', $this->data);
}
例如,当我打开页面day = Sunday hour = 12 pm时,如果我更改了joseph或macro,则必须在表格中更改此值。