Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!