Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. function salvar(){
  2. $.ajax({
  3. type: 'POST',
  4. dataType: 'json',
  5. data: {operationType: 'insert', nome: $('#nome').val(), sobrenome: $('#sobrenome').val(), idade: $('#idade').val() },
  6. url: 'http://localhost/projetos/wstest/cadastrar.php',
  7. ContentType: 'application/json',
  8. success: function(response){
  9. alert('Resposta: '+JSON.stringify(response));
  10. },
  11. error: function(err){
  12. alert('Resposta: '+JSON.stringify(err));
  13. alert('Erro ao inserir registro!');
  14. }
  15. });}
  16.  
  17. if ($_POST['operatioType'] == "insert")
  18. {
  19. $query = "INSERT INTO `usuario`(`nome`, `sobrenome`, `idade`) "
  20. . "VALUES ('$nome','$sobrenome','$idade')";
  21.  
  22. $res = mysqli_query($link, $query);
  23.  
  24. if ($res == true)
  25. {
  26. $resultado = 1;
  27.  
  28. return $resultado;
  29. }
  30. else
  31. {
  32. $resultado = 0;
  33.  
  34. return $resultado;
  35. }
  36.  
  37. echo json_encode($resultado);
  38. }
  39.  
  40. else if($_POST['operationType'] == "login")
  41. {
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement