• Dear kawan2 saya mohon pencerahan disini
    saya mencoba membuat plugin yg menggunakan ajax tetapi selalu return 0

    berikut adalah kode yg saya pakai

    <script type=”text/javascript”>
    jQuery(document).ready(function(){
    jQuery(“#mailinglist”).submit(function() {
    if(jQuery(“#mailinglistemail”).val()==””) {
    jQuery(“#mailinglist #message”).text(“Please enter your email address.”);
    return false;
    } else {
    var email = jQuery(‘#mailinglistemail’).val();
    if(email.indexOf(“@”) == -1 || email.indexOf(“.”) == -1) {
    jQuery(“#mailinglist #message”).text(“Please enter a valid email address.”);
    return false;
    } else {
    console.log(“email :” + email);
    var data = {
    action: ‘join_mailinglist’,
    email: email
    };
    jQuery(“#mailinglistsubmit”).hide();
    jQuery(“.ajaxsave”).show();
    jQuery.post(“<?php echo admin_url(‘admin-ajax.php’); ?>”, data,
    function(response){
    jQuery(“.ajaxsave”).hide();
    jQuery(“#mailinglistsubmit”).show();
    jQuery(“#mailinglist #message”).html(response);
    console.log(response);
    alert(response);
    });
    return false;
    }
    }

    });
    });
    </script>
    <form method=”post” id=”mailinglist” action=””>
    <div id=”message”></div>
    <input type=”text” name=”mailinglistemail” id=”mailinglistemail” />
    <input type=”submit” name=”submit” id=”mailinglistsubmit” value=”Join” /><img src=”<?php admin_url(); ?>/wp-admin/images/wpspin_light.gif” alt=”” class=”ajaxsave” style=”display: none;” />
    </form>

    dan satu file lagi di file admin :
    add_action(‘wp_ajax_join_mailinglist’, ‘join_mailinglist_callback’);
    add_action(‘wp_ajax_nopriv_join_mailinglist’, ‘join_mailinglist_callback’);

    function join_mailinglist_callback() {
    global $wpdb;
    $email = $_POST[‘email’];
    echo $email;

    die();
    }

    mohon koreksi code saya + pencerahannya
    any comment would be appreciated

    Thanks

Melihat 2 balasan - 1 sampai 2 (dari total 2)
Melihat 2 balasan - 1 sampai 2 (dari total 2)
  • Topik ‘ajax selalu return 0’ tertutup untuk balasan baru.