0
I have a form through a modal, where it performs updates in the Mysql database. However, there are times when clicking on "Forward" the action is not executed, and at other times the action works normally without any problem. So I was wondering if there is something wrong with my Javascript, since it has hours that it works smoothly and other 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>
It displays some error on your console when it is not running?
– Rafael Withoeft
POST http://localhost/systemProtocolo/protocol/updatetramitacao [HTTP/1.1 500 Internal Server Error 47 ms Gave this error.
– Andrew Maxwell
As you asked about your javascript, to my view is not in trouble. There is some bug in your update function, you have some IDE to "debug" step by step what happens in it and see where exactly the error happens?
– Rafael Withoeft
I’m using the Netbeans!!
– Andrew Maxwell
Do you have Xdebug enabled and working? Put a breakpoint at the beginning of the function right on this line:
$dados['area_id'] = $this->input->post('area');
and gives F8 until the bug happens and see through the debug window which was the error that happened... or tries to put atry catch(\Exception $e) {}
generic to catch the error. Looking like this I can’t say what the error might be... but there are some things there that you should take care of, such as string concatenation to form SQL.– Rafael Withoeft
I’ll check here, anything comment, vlw for help ;)
– Andrew Maxwell
It was solved, it was a detail! VLW ;)
– Andrew Maxwell