Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function salvar(){
- $.ajax({
- type: 'POST',
- dataType: 'json',
- data: {operationType: 'insert', nome: $('#nome').val(), sobrenome: $('#sobrenome').val(), idade: $('#idade').val() },
- url: 'http://localhost/projetos/wstest/cadastrar.php',
- ContentType: 'application/json',
- success: function(response){
- alert('Resposta: '+JSON.stringify(response));
- },
- error: function(err){
- alert('Resposta: '+JSON.stringify(err));
- alert('Erro ao inserir registro!');
- }
- });}
- if ($_POST['operatioType'] == "insert")
- {
- $query = "INSERT INTO `usuario`(`nome`, `sobrenome`, `idade`) "
- . "VALUES ('$nome','$sobrenome','$idade')";
- $res = mysqli_query($link, $query);
- if ($res == true)
- {
- $resultado = 1;
- return $resultado;
- }
- else
- {
- $resultado = 0;
- return $resultado;
- }
- echo json_encode($resultado);
- }
- else if($_POST['operationType'] == "login")
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement