Yupiter Aryo
Yupiter Aryo

Reputation: 11

jquery ajax not catch the data back

I have this jquery ajax script

$.ajax({
    type: "POST",
    url: "register.php",
    data: "name=" + name + "&email=" + email + "&password=" + password + "&confirm_password=" + confirm_password + "&captcha=" + captcha,
    success: function(data){
    if(data == "Success"){
      $("#tombol_submit").remove();
      $("#register_sukses").fadeIn(500);
    }else{
      $("#register_gagal").html(data).fadeIn(500);
      $("#submit").removeAttr("disabled").attr("value", "Submit");
    }
}

in the register.php, once the data successfully added to database, it will echo the "Success" word, the word Success is appear in the form page, but the button (tombol_submit) not removed, otherwise it back into Submit button (just like in 'else' statement). How to remove the button, so the client cannot click the submit button again?

here's the register.php script

<?php
    session_start();
    include "config/koneksi.php";

    if(!empty($_POST['captcha'])){
         if($_POST['captcha'] == $_SESSION['hasil']){
             $fullname = $_POST['name'];
             $email = $_POST['email'];
             $password = md5($_POST['password']);

             $queryform = "INSERT INTO register (fullname,email,pass) 
                    VALUES('$fullname','$email','$password')";
             if ($hasilform = mysqli_query($konek2, $queryform)) {
                 echo "Success";
             } else {
                 echo "Failed";
             }
         } else {
             echo "The captcha code is wrong";
         }
     } else {
         echo "The captcha cannot be empty";
     }
?>

Upvotes: 0

Views: 64

Answers (4)

Shaik Matheen
Shaik Matheen

Reputation: 1307

i think id "tombol_submit" is not exit

Check console for error,

then based on error you can fix the problem.

Upvotes: 0

Ryan Hu
Ryan Hu

Reputation: 330

Normally $().remove() will work.

If you are asking why this if...else... doesn't work and always goes to else, please check the response from your backend to make sure the response is only a "Success" string.

Upvotes: 2

Bhavik
Bhavik

Reputation: 503

use this:

$("#tombol_submit").hide();

Upvotes: 0

Bharat
Bharat

Reputation: 2464

You can try like this

$("#tombol_submit").css("display","none");

Upvotes: 0

Related Questions