I have a form through a modal, where it makes updates to the MySQL database. However, there are moments when clicking "Forward" the action is not executed, and at other times the action works normally, without no problem. So I wanted to know if there is anything wrong with my JavaScript, since it has hours that it works quietly and some not.
JavaScript:
<script type="text/javascript">
$(document).ready(function () {
$('#salvar').click(function () {
var destino = "<?php echo base_url('protocolo/updatetramitacao') ?>";
var dados = {
'area': $("#area").val(),
'status': $('#status').val(),
'idhistorico': $('#hidden').val()
};
$.ajax({
type: "POST",
url: destino,
data: dados,
success: function (response) {
alert('Protocolo encaminhado com sucesso!');
location.reload();
}
});
return false;
});
});
Update function:
public function updatetramitacao(){
$dados['area_id'] = $this->input->post('area');
$dados['situacao_id'] = $this->input->post('status');
$this->protocolo->atualizarhistorico($dados, array('protocolo_id' => $this->input->post('idhistorico')));
$resultdados = $this->db->query('SELECT datap FROM historico WHERE protocolo_id ='.$this->input->post('idhistorico'));
$resulthistorico = $resultdados->row();
$this->db->query('UPDATE historico set datat = NOW() WHERE protocolo_id = '. $this->input->post('idhistorico')
. ' AND datat is null');
$dados10['protocolo_id'] = $this->input->post('idhistorico');
$dados10['area_id'] = $this->input->post('area');
$dados10['situacao_id'] = $this->input->post('status');
$dados10['datap'] = $resulthistorico->datap;
$this->protocolo->do_insert_historicos($dados10);
$response = array("success" => true);
echo json_encode($response);
}
Form:
<?php
$id = $this->uri->segment(3);
if ($id > 0) {
$querys = $this->protocolo->get_protocol_hist($id)->row();
?>
<form action="" id="user2">
<fieldset>
<legend>Encaminhar protocolo</legend>
<div class="row">
<div class="small-6 columns">
<div class="row">
<div class="small-12 columns">
<label for="pt">Protocolo</label>
<input type="text" name="protocolo" id="protocolo" disabled="disabled" value="<?php echo $querys->id ?>">
</div>
</div>
<div class="row">
<div class="small-12 columns">
<label for="area">Área</label>
<select name="area" id="area">
<?php
$array = array();
$query = $this->area->get_all_areas()->result();
foreach ($query as $area) {
?>
<option value="<?php echo $area->id ?>"><?php echo $area->area ?></option>
<?php } ?>
</select>
</div>
</div>
</div>
<div class="small-6 columns">
<div class="row">
<div class="small-12 columns">
<label for="numero">Número do documento</label>
<input type="text" name="documento" id="documento" disabled="disabled" value="<?php echo $querys->numerodocumento ?>">
</div>
</div>
<div class="row">
<div class="small-12 columns">
<label for="status">Status</label>
<select name="status" id="status">
<?php
$array = array();
$query = $this->situacao->get_all_situacao()->result();
foreach ($query as $linha) {
?>
<option value="<?php echo $linha->id ?>"><?php echo $linha->situacao ?></option>
<?php } ?>
</select>
</div>
</div>
<input type="button" value="Encaminhar" id="salvar" class="button small font encaminhar radius">
</div>
<a class="close-reveal-modal">×</a>
</div>
<input type="hidden" id="hidden" name="idhistorico" value="<?php echo $querys->id; ?>">
</fieldset>
</form>