i am using custom plugin to display the values.

my plugin file is

add_action('wp_ajax_my_action', 'my_action_callback');
function my_action_callback(){
    check_ajax_referer('my_ajax_nonce');    
    include('my_action.php');
}

my_action.php file is

<?php
global $wpdb;
        $name = $_POST['test'];
        $city = $_POST['test1'];
        $date = $_POST['test2'];
        if ($date != '') {
            $enddate = date("Y-m-t", strtotime($date));
            $dates_sql = " AND start_date <= '$date' ";
            }
            if ($city != '' && $city != -1) 
            $destination_sql = "AND venue = '$city'";
            if ($name != '' && $name != -1) 
                $origincity_sql = "AND event_name = '$name'";
        $query = " SELECT * FROM <table name> WHERE event_id!='' " . $dates_sql . " " . $destination_sql . " " . $origincity_sql . " ORDER BY start_date DESC ";
        $results = $wpdb->get_results($query) or die(mysql_error());    
        foreach ($results as $row)
        {
            $message  = "<tr><td align='center' id = 'username'>".$row->username."</td><td align='center' id = 'eventname'>".$row->event_name."</td><td align='center' id = 'venue'>". $row->venue."</td><td align='center' id = 'email'>".$row->email."</td><td align='center' id = 'misseddays'>".$row->missed_days."</td><td align='center' id = 'paymentstatus'>".$row->payment_mode."</td><td align='center' id = 'amountpaid'>".$row->amount_paid."</td><td align='center' id = 'amountbalance'>".$row->amount_balance."</td><td align='center' id = 'mailsent'>".=$row->mail."</td></tr>";
        }  
        header('Content-Type: application/json');
        echo json_encode($message);
?>

my jquery file is

<script type='text/javascript'>
                        jQuery("#searchsubmit").click( function(e) {
                         var data = {
                                    action: 'my_action',
                                _ajax_nonce: '<?php echo wp_create_nonce( 'my_ajax_nonce' ); ?>',
                                test:jQuery("#eventname").val(),
                                test1:jQuery("#city").val(),
                                test2:jQuery("#datepicker").val()
                                    };
                            jQuery.post(ajaxurl, data, function(response) {
        (#users).html(response);
    });
                                });
                    </script>

i am not getting the response in the html file despite it is redirecting to home page.
any changes to be done please help

Read more here: ajax request not returning the result


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , ,

Wordpress related questions and answers: