Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

154
Vistas
ajax if result = 1 show message in div

I want when the result is 1 DIV showed

my php code

   if($FileType != "zip" && $FileType != "ZIP") {
       echo '1';
    }

my html form code

<form id="my-form" method="post" enctype="multipart/form-data">

 <textarea id="_text" name="text" required=""></textarea>
 <input id="_from" name="from" type="hidden" value="<?php echo $id; ?>"/>
 <input name="to" type="hidden" value="<?php echo $touser; ?>"/>
 <input name="post" type="hidden" value="<?php echo $postid ?>"  />

 <div class="file">
 <li>ملفات .zip فقط</li>
 <input class="up" type="file" name="up" />
 </div>


 <button class="submit">submit</button>

</form>

my javascript code

<script>
$( '#my-form' )
.submit( function( e ) {
$.ajax({
    url: 'chat_a.php',
    type: 'POST',
    data: new FormData( this ),
    processData: false,
    contentType: false
} );
e.preventDefault();
document.getElementById("my-form").reset();
});
</script>

I want when the result is 1 DIV showed

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Add a success handler:

$.ajax({
    url: 'chat_a.php',
    type: 'POST',
    data: new FormData( this ),
    processData: false,
    contentType: false,
    success:function(response){
        if(response == "1")
        {
         // DO YOUR STUFF
        }
    }
} );

UPDATE: add the comma after contentType: false.

I have already done that in the answer.

over 4 years ago · Santiago Trujillo Denunciar

0

You need to add a success or done function (depending on the version of jQuery). For the latest versions you would use done:

$.ajax({
    url: 'chat_a.php',
    type: 'POST',
    data: new FormData( this ),
    processData: false,
    contentType: false
})
  .done(function( msg ) {
    if(msg == '1') {
         // your code here
     }
});

From the docs -

Deprecation Notice: The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks are removed as of jQuery 3.0. You can use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda