Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] UPDATE o INSERT con alert de confirmación

Estas en el tema de UPDATE o INSERT con alert de confirmación en el foro de PHP en Foros del Web. Cita: Iniciado por xfxstudios yo utilizo ajax para esas cositas: @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código Javascript : Ver original /*Cargo las variables con los datos del formulario*/ ...

  #31 (permalink)  
Antiguo 02/03/2016, 15:54
 
Fecha de Ingreso: julio-2013
Mensajes: 174
Antigüedad: 10 años, 9 meses
Puntos: 1
Respuesta: UPDATE o INSERT con alert de confirmación

Cita:
Iniciado por xfxstudios Ver Mensaje
yo utilizo ajax para esas cositas:

Código Javascript:
Ver original
  1. /*Cargo las variables con los datos del formulario*/
  2.  
  3. function registraUsuario(){
  4. var nombre = document.regi.nombre.value;
  5. var email = document.regi.usuario.value;
  6. var celular = document.regi.celular.value;
  7. var clave = document.regi.clave.value;
  8.  
  9. /*Verifico que los campos no esten vacios, de ser asi, emito una alerta al usuario*/
  10.  
  11. if(nombre == ""){
  12.     new PNotify({
  13.     title: 'Atención',
  14.     text: 'El campo NOMBRE esta vacio.',
  15.     type: 'info'
  16. });
  17. }else if(email == ""){
  18.     new PNotify({
  19.     title: 'Atención',
  20.     text: 'El campo Email esta vacio.',
  21.     type: 'info'
  22. });
  23. }else if(clave == ""){
  24.     new PNotify({
  25.     title: 'Atención',
  26.     text: 'El campo NOMBRE esta vacio.',
  27.     type: 'info'
  28. });
  29.  
  30. /*Si todo esta bien continuo con el registro*/
  31. }else{
  32.         $.ajax({
  33. /*Envio la informacion al php que realizará el procedimiento*/
  34.  
  35.             url: 'core/nuevo_user.php?tipo=registra&nombre='+nombre+'&email='+email+'&celular='+celular+'&clave='+clave,
  36.             type: 'get',
  37.             success: function (dato) {
  38. /*Recibo un json como respuesta*/              
  39. var dato = eval('(' + dato + ')');
  40.  
  41. /*Verifico el codigo recibido en el json y emito la alerta correspondiente*/
  42. if(dato.codigo == "205"){
  43.             new PNotify({
  44.     title: 'Info',
  45.     text: dato.mensaje,
  46.     type: 'warning'
  47. });
  48. }else if(dato.codigo == "200"){
  49.             new PNotify({
  50.     title: 'Info',
  51.     text: dato.mensaje,
  52.     type: 'info'
  53. });
  54.  
  55. /*Cargo la lista de usuarios*/
  56. lista();
  57.  
  58. /*Limpio los campos del formulario*/
  59. document.regi.nombre.value = '';
  60. document.regi.usuario.value = '';
  61. document.regi.celular.value = '';
  62. document.regi.clave.value = '';
  63.             }
  64.             }
  65.         });
  66.  
  67.     }
  68. }

y listo funciona perfecto coin cualquier alerta o lo que quieras implementar
Lo cierto es que analizándolo bien... no me parece complicado de entender y, como dices, es más limpio y recarga menos la página seguro.
Lo que no entiendo es el json, de donde recibes el código (dato) y lo compruebas con ... ¿qué cosa? 205 se refiere a erro y 200 a success ... o son datos de la BD? Eso no me queda claro...aunque como te digo no he usado nunca esta programación.
  #32 (permalink)  
Antiguo 02/03/2016, 16:46
Avatar de xfxstudios  
Fecha de Ingreso: junio-2015
Ubicación: Valencia - Venezuela
Mensajes: 2.448
Antigüedad: 8 años, 10 meses
Puntos: 263
Respuesta: UPDATE o INSERT con alert de confirmación

son datos que creas al momento de ejecutar la query en el php, por ejemplo:
Código PHP:
Ver original
  1. $info = array();
  2.  
  3. $info['codigo'] = "200";
  4. $info['mensaje'] = "mensaje";
  5.  
  6. echo json_encode($info);

alli por ejemplo estoy pasandole los parametros al ajax para identificar si la query se realizo con exito o no. Puedes pasar tantos datos necesites y utilizarlos como necesites con el ajax
__________________
[email protected]
HITCEL
  #33 (permalink)  
Antiguo 02/03/2016, 19:59
 
Fecha de Ingreso: julio-2013
Mensajes: 174
Antigüedad: 10 años, 9 meses
Puntos: 1
Respuesta: UPDATE o INSERT con alert de confirmación

Cita:
Iniciado por xfxstudios Ver Mensaje
yo trabajo mejor con ajax y sin recargar la pagina lo cual dejo para cuando tienen desactivado el js actualizo listas datos y todo en una sola consulta, es cuestión de darle de a poco, aunque la solu que te pase era mucho mas sencilla y la podrias haber adaptado a las validaciones (que no mostraste para ayudarte mejor con el codigo), lo digo porque en dispositivos mobiles donde la señal es un poco tosca en ocasiones una web con tantas redirecciones termina pesando un poco, mientras que ajax da la sensación de que no recarga nada.

Tu solución la utilice en algún momento con esa misma libreria pero ya no, utilizo otras como Alertify.js o PNotifi también es buena y fácil de implementar.

Saludos y buena por esa.!
Pero no entiendo que tengo que implementar en mi código. He descargado el .css y el .js, los he agregado a la web y he colocado las funciones de la siguiente manera. Ewsta todo por default
Código Javascript:
Ver original
  1. <script type="text/javascript" src="js/2.1.3_jquery_min.js"></script>(((QUIZA ESTE SOBRA)))
  2. <script type="text/javascript" src="js/pnotify.custom.min.js"></script>
  3. <link rel="stylesheet" type="text/css" href="css/pnotify.custom.min.css"/>
  4.  
  5.  
  6. <!-- FUNCIONES PARA VENTANAS PNOTIFY -->
  7. <script type="text/javascript">
  8. new PNotify({
  9.     title: 'Bright Theme Notice',
  10.     text: 'Look at my beautiful styling! ^_^',
  11.     styling: 'brighttheme'
  12. });
  13. new PNotify({
  14.     title: 'Bright Theme Info',
  15.     text: 'Look at my beautiful styling! ^_^',
  16.     type: 'info',
  17.     styling: 'brighttheme'
  18. });
  19. new PNotify({
  20.     title: 'Bright Theme Success',
  21.     text: 'Look at my beautiful styling! ^_^',
  22.     type: 'success',
  23.     styling: 'brighttheme'
  24. });
  25. new PNotify({
  26.     title: 'Bright Theme Error',
  27.     text: 'Look at my beautiful styling! ^_^',
  28.     type: 'error',
  29.     styling: 'brighttheme'
  30. });
  31. new PNotify({
  32.     title: 'Bootstrap Notice',
  33.     text: 'Look at my beautiful styling! ^_^',
  34.     styling: 'bootstrap3'
  35. });
  36. new PNotify({
  37.     title: 'Bootstrap Info',
  38.     text: 'Look at my beautiful styling! ^_^',
  39.     type: 'info',
  40.     styling: 'bootstrap3'
  41. });
  42. new PNotify({
  43.     title: 'Bootstrap Success',
  44.     text: 'Look at my beautiful styling! ^_^',
  45.     type: 'success',
  46.     styling: 'bootstrap3'
  47. });
  48. new PNotify({
  49.     title: 'Bootstrap Error',
  50.     text: 'Look at my beautiful styling! ^_^',
  51.     type: 'error',
  52.     styling: 'bootstrap3'
  53. });
  54. new PNotify({
  55.     title: 'Font Awesome Notice',
  56.     text: 'Look at my beautiful styling! ^_^',
  57.     styling: 'fontawesome'
  58. });
  59. new PNotify({
  60.     title: 'Font Awesome Info',
  61.     text: 'Look at my beautiful styling! ^_^',
  62.     type: 'info',
  63.     styling: 'fontawesome'
  64. });
  65. new PNotify({
  66.     title: 'Font Awesome Success',
  67.     text: 'Look at my beautiful styling! ^_^',
  68.     type: 'success',
  69.     styling: 'fontawesome'
  70. });
  71. new PNotify({
  72.     title: 'Font Awesome Error',
  73.     text: 'Look at my beautiful styling! ^_^',
  74.     type: 'error',
  75.     styling: 'fontawesome'
  76. });
  77. new PNotify({
  78.     title: 'jQuery UI Notice',
  79.     text: 'Look at my beautiful styling! ^_^',
  80.     styling: 'jqueryui'
  81. });
  82. new PNotify({
  83.     title: 'jQuery UI Info',
  84.     text: 'Look at my beautiful styling! ^_^',
  85.     type: 'info',
  86.     styling: 'jqueryui'
  87. });
  88. new PNotify({
  89.     title: 'jQuery UI Success',
  90.     text: 'Look at my beautiful styling! ^_^',
  91.     type: 'success',
  92.     styling: 'jqueryui'
  93. });
  94. new PNotify({
  95.     title: 'jQuery UI Error',
  96.     text: 'Look at my beautiful styling! ^_^',
  97.     type: 'error',
  98.     styling: 'jqueryui'
  99. });
  100. </script>

Pero como agrego botones para llamar a estas funciones. He visitado la web y parece que hay que descargar más .js ... ¿que necesito?
  #34 (permalink)  
Antiguo 06/03/2016, 11:40
 
Fecha de Ingreso: julio-2011
Ubicación: Los Rios
Mensajes: 145
Antigüedad: 12 años, 9 meses
Puntos: 10
Respuesta: UPDATE o INSERT con alert de confirmación

Lo resolvi colocando
Código PHP:
Ver original
  1. if ($Result1){
  2. //OK
  3. echo "<script>swal('Correcto','Video subido correctamente', 'success')</script>";
  4. } else {
  5. //Error
  6. }
en el body
__________________
___________________________
Si te ayudo mi respuesta dale al +1

Etiquetas: insert, javascript, update
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:26.