2
I am using a form inside a bootstrap modal. It makes a record in the database and returns the message whether or not it has registered. I have inspected the element several times and everything is right. Except for a jquery plugin called toastr that does not appear. How can I check if this plugin (which is a notification plugin) is working, since all information go back and forth via Ajax?
Follow the plugin link I’m using
http://codeseven.github.io/toastr/demo.html
Follow my codes:
php student.
// continuação do código
success: function (result) {
var retorno = JSON.parse(result);
var tipo = retorno[0].tipo;
var msg = retorno[0].mensagem;
if (tipo == 'success') {
toastr[tipo](msg);
alert(msg);
$('form')[0].reset();
$(".modal").modal("hide");
} else if (tipo == 'error') {
toastr[tipo](msg);
alert(msg);
}
}
cadastraAluno.php
<?php
require_once '../class/Conexao.php';
require_once '../class/Aluno.php';
$nome = utf8_decode($_POST['nome']);
$matricula = utf8_decode($_POST['matricula']);
$anosemestre = utf8_decode($_POST['anosemestre']);
try {
$conexao = new Conexao();
$conexao->abrirConexao();
$aluno = new Aluno();
$aluno->setNome($nome);
$aluno->setMatricula($matricula);
$aluno->setAnoSemestre($anosemestre);
$ano = date("Y");
$query = "INSERT INTO aluno (nomeAluno, matricula, ano_inscrito, ano_semestre, flag_ativo)";
$query .= " VALUES ('{$aluno->getNome()}', '{$aluno->getMatricula()}', '$ano', '{$aluno->getAnoSemestre()}', 1)";
$result = mysqli_query($conexao->abrirConexao(), $query);
$resultado[] = array('tipo'=>'success','mensagem'=>'Aluno cadastrado com sucesso!');
echo json_encode($resultado);
} catch (Exception $ex) {
$resultado[] = array('tipo'=>'error','mensagem'=>'Não foi possível cadastrar o aluno');
echo json_encode($resultado);
} finally {
$conexao->fecharConexao();
}
The Connection and Student classes work well and the registration is done in the bank. The toastr is called in the following line:
<script src="js/toastr.js" type="text/javascript"></script>
It is the only thing that is not working. Notification does not appear.
The question is not nothingness clear and is impossible reply without hacking your computer to see your code...
– brasofilo
I’ll improve by putting code
– DiChrist
improved the question brasofilo
– DiChrist
beauty, just a couple of tips, this guide is kind important: How to create a Minimum, Complete and Verifiable example; and make a headline that attracts attention too, your intention is to make a craque read the question and give an answer, right? Then, take care of the descriptive title and the explanation/code to the point; otherwise there are answers in the chutômetro and a lot of comments asking for more details/explanations.... good luck!
– brasofilo
I’ll follow the recommendations, thank you.
– DiChrist
Have you tried debugging that
success
to see if he’s really called?– Leonel Sanches da Silva
Yes Gypsy, and he calls yes.
– DiChrist