Foros del Web » Creando para Internet » Sistemas de gestión de contenidos » WordPress »

¿Como puedo hacer que este código Ajax funcione en Wordpress?

Estas en el tema de ¿Como puedo hacer que este código Ajax funcione en Wordpress? en el foro de WordPress en Foros del Web. Este código Ajax no funciona dentro de Wordpress, ¿Qué tengo que hacer para que funcione? Anexo todo el javascript donde está el Ajax. @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); ...
  #1 (permalink)  
Antiguo 18/09/2012, 13:50
 
Fecha de Ingreso: diciembre-2008
Mensajes: 738
Antigüedad: 15 años, 4 meses
Puntos: 15
¿Como puedo hacer que este código Ajax funcione en Wordpress?

Este código Ajax no funciona dentro de Wordpress, ¿Qué tengo que hacer para que funcione? Anexo todo el javascript donde está el Ajax.

Código Javascript:
Ver original
  1. var messageDelay = 2000;  // How long to display status messages (in milliseconds)
  2.  
  3. // Init the form once the document is ready
  4. $( init );
  5.  
  6.  
  7. // Initialize the form
  8.  
  9. function init() {
  10.  
  11.   // Hide the form initially.
  12.   // Make submitForm() the form's submit handler.
  13.   // Position the form so it sits in the centre of the browser window.
  14.   $('#contactForm').hide().submit( submitForm ).addClass( 'positioned' );
  15.  
  16.   // When the "Send us an email" link is clicked:
  17.   // 1. Fade the content out
  18.   // 2. Display the form
  19.   // 3. Move focus to the first field
  20.   // 4. Prevent the link being followed
  21.  
  22.   $('a[href="#contactForm"]').click( function() {
  23.     $('#content').fadeTo( 'slow', .2 );
  24.     $('#contactForm').fadeIn( 'slow', function() {
  25.       $('#senderName').focus();
  26.     } )
  27.  
  28.     return false;
  29.   } );
  30.  
  31.   // When the "Cancel" button is clicked, close the form
  32.   $('#cancel').click( function() {
  33.     $('#contactForm').fadeOut();
  34.     $('#content').fadeTo( 'slow', 1 );
  35.   } );  
  36.  
  37.   // When the "Escape" key is pressed, close the form
  38.   $('#contactForm').keydown( function( event ) {
  39.     if ( event.which == 27 ) {
  40.       $('#contactForm').fadeOut();
  41.       $('#content').fadeTo( 'slow', 1 );
  42.     }
  43.   } );
  44.  
  45. }
  46.  
  47.  
  48. // Submit the form via Ajax
  49.  
  50. function submitForm() {
  51.   var contactForm = $(this);
  52.  
  53.   // Are all the fields filled in?
  54.  
  55.   if ( !$('#senderName').val() || !$('#senderEmail').val() || !$('#message').val() ) {
  56.  
  57.     // No; display a warning message and return to the form
  58.     $('#incompleteMessage').fadeIn().delay(messageDelay).fadeOut();
  59.     contactForm.fadeOut().delay(messageDelay).fadeIn();
  60.  
  61.   } else {
  62.  
  63.     // Yes; submit the form to the PHP script via Ajax
  64.  
  65.     $('#sendingMessage').fadeIn();
  66.     contactForm.fadeOut();
  67.  
  68.     $.ajax( {
  69.       url: contactForm.attr( 'action' ) + "?ajax=true",
  70.       type: contactForm.attr( 'method' ),
  71.       data: contactForm.serialize(),
  72.       success: submitFinished
  73.     } );
  74.   }
  75.  
  76.   // Prevent the default form submission occurring
  77.   return false;
  78. }
  79.  
  80.  
  81. // Handle the Ajax response
  82.  
  83. function submitFinished( response ) {
  84.   response = $.trim( response );
  85.   $('#sendingMessage').fadeOut();
  86.  
  87.   if ( response == "success" ) {
  88.  
  89.     // Form submitted successfully:
  90.     // 1. Display the success message
  91.     // 2. Clear the form fields
  92.     // 3. Fade the content back in
  93.  
  94.     $('#successMessage').fadeIn().delay(messageDelay).fadeOut();
  95.     $('#senderName').val( "" );
  96.     $('#senderEmail').val( "" );
  97.     $('#message').val( "" );
  98.  
  99.     $('#content').delay(messageDelay+500).fadeTo( 'slow', 1 );
  100.  
  101.   } else {
  102.  
  103.     // Form submission failed: Display the failure message,
  104.     // then redisplay the form
  105.     $('#failureMessage').fadeIn().delay(messageDelay).fadeOut();
  106.     $('#contactForm').delay(messageDelay+500).fadeIn();
  107.   }
  108. }
  #2 (permalink)  
Antiguo 19/09/2012, 02:14
Avatar de hasdpk  
Fecha de Ingreso: agosto-2011
Ubicación: $spain->city( 'Arucas' );
Mensajes: 1.800
Antigüedad: 12 años, 8 meses
Puntos: 297
Respuesta: ¿Como puedo hacer que este código Ajax funcione en Wordpress?

¿En qué parte de wordpress lo quieres poner, administración o en la portada/sección? ¿Ya has cargado con anterioridad jQuery?
__________________
Freelance Developer — www.rubenmartin.me PHP, SQL, Wordpress, Prestashop, Codeigniter, Laravel
RegaloConsolas — www.regaloconsolas.com Sorteo juegos, consolas y accesorios

Etiquetas: ajax, php
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 12:43.