Ver Mensaje Individual
  #11 (permalink)  
Antiguo 08/04/2012, 14:33
Avatar de Jemonge
Jemonge
 
Fecha de Ingreso: enero-2011
Mensajes: 28
Antigüedad: 13 años, 3 meses
Puntos: 0
Respuesta: Problema al procesar string

Cita:
Iniciado por elarrieux Ver Mensaje
Podremos ver el codigo?

Estas haciendo alguna conversion en la llamada al ajax? Asignando content type al ajax?

Sds.
Ok, estos son los archivos que utilizo:


Index.html

Código HTML:
Ver original
  1. <!DOCTYPE html>
  2.  
  3. <html lang="es">
  4.     <head>
  5.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  6.         <script src="http://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript"></script>
  7.         <script type="text/javascript" src="acciones.js"></script>
  8.     </head>
  9.  
  10.     <body style="text-align: center;">
  11.         <div style="text-align: left; width: 500px; margin: 0 auto;">
  12.             <form action="" method="post" accept-charset="UTF-8" name="postedit">
  13.                 <div style="float:left; color:#0D7200; font-weight: bold; margin-bottom:3px;">
  14.                     <div style="display:inline-block; margin-left:5px;">
  15.                         Categoria:
  16.                     </div>
  17.                     <div style="display:inline-block; margin-left:5px;">
  18.                         <input id="EditCategoria" class="inputPublicar" style="height: 20px; margin-left: -5px;" type="text" maxlength="25" value="Música">
  19.                     </div>
  20.                 </div>
  21.                 <div id="focusEditar">
  22.                     <input class="login" type="submit" style="float:right;" name="postEdit" id="postEdit" value="Guardar" onclick="return Guardar(this.form.EditCategoria.value);" tabindex="2">
  23.                 </div>
  24.             </form>
  25.         </div>
  26.     </body>
  27. </html>


acciones.js

Código Javascript:
Ver original
  1. function Guardar(categoria)
  2. {
  3.     if(categoria == "")
  4.     {
  5.         alert("Ingresa una categoria");
  6.  
  7.         return false;
  8.     }
  9.     else
  10.     {
  11.         $.ajax({
  12.        
  13.             type: 'POST',
  14.             url: 'http://localhost/pagina/Guardar.php',
  15.             data: 'categoria='+ encodeURIComponent(categoria),
  16.  
  17.             success: function(h){
  18.                 $("#EditCategoria").val(h);
  19.             },
  20.  
  21.             error: function(){
  22.                
  23.             }
  24.         });
  25.         return false;
  26.     }
  27. }


Guardar.php

Código PHP:
Ver original
  1. <?php
  2.  
  3.         $categoria = $_POST['categoria'];
  4.         //Limpiar
  5.         $categoria = preg_replace("/[^a-z ñáéíóú]/i", "", $categoria);
  6.        
  7.         echo $categoria." *";
  8. ?>