• Hello Everyone
    I have been working on this code for the past couple of days and I have not been able to trace the cause of the problem. I am trying to do ajax call through a shortcode but to no success, the result has always been 0.
    Here are the codes:`
    <strong>playPlugin.js</strong>
    jQuery(document).ready(function($){
    //alert(“Hello from the play plugin”); just to test if it is working
    $(‘#mail’).click(function(){
    var textBox = $(‘#chimp-mail’).val();
    // alert(textBox+” was entered”);
    var data = {
    action:’ajaxer’,
    ‘chimp-mail’:textBox
    };

    jQuery.ajax({
    url: myAjax.ajaxurl,
    type: ‘POST’,
    data: data,
    success: function (response) {
    if (response) {
    jQuery(“#ajaxresults”).html(response);
    }
    }
    });
    });
    }

    );

    <strong>index.php</strong>

    global $playDir;
    $playDir = WP_PLUGIN_URL.”/playPlugin/” ;
    function playPluginScripts() {
    //All Scripts goes in here
    global $playDir;
    $src = $playDir.’playPlugin.js’;
    wp_enqueue_script(‘jquery’);
    wp_enqueue_script(‘playPlugiScripts’, $src, array(‘jquery’)) ;
    //wp_enqueue_script(‘playPluginScripts’);
    wp_localize_script( ‘playPlugiScripts’, ‘myAjax’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ )));

    }

    function ajaxer(){
    if (isset($_POST[‘chimp-mail’])) {
    echo “You entered <b>” . $_POST[‘chimp-mail’] . “</b>”;
    die();
    }
    }
    //add_action(‘wp_ajax_nonpriv_ajaxerl’,’ajaxer’);
    add_action(‘wp_ajax_ajaxerl’,’ajaxer’);

    function habeelety() {
    ?>
    <form id=”mail-form” method=”post” action=””>
    <label for=”chimp-mail”>Enter your Name</label>
    <input class=”chimp-mail” type=”text” placeholder=”[email protected]” name=”chimp-mail” id=”chimp-mail”/>
    <input id=”mail” type=”button” value=”Subscribe” name=”mail” />
    </form>
    <div id=”ajaxresults”></div>
    <?php

    }

    add_action(‘wp_print_scripts’, ‘playPluginScripts’);
    add_shortcode(‘habeeletycode’, habeelety);
    `

    Help what am I doing wrong?

  • The topic ‘Jquery Ajax returning empty result’ is closed to new replies.