13 March 2020

How to get multiple values from ajax in wordpress?

Get multiple values from ajax in wordpress.





Paste this code in main file. 


function single_user_data(){
var ajax = "http://wpcodekit.com/wp-admin/admin-ajax.php";
   var data = {
'action' : "get_single_use",
'ID': user_id
}
$.post(ajax,data,function(response){
var result = $.parseJSON(response)
$(".first").html(result[0]);
$(".second").html(result[1]);
console.log(response);
});
}
single_user_data();




Paste this code in function.php file.



 function get_single_use(){
 
  $user_id = $_POST['ID'];
  if(function_exists('date_default_timezone_set')) {
date_default_timezone_set("Asia/Kolkata");
}

// then use the date functions, not the other way around
$date = date("d/m/Y");
$date1 =  date("H:i a");

global $wpdb;
$table_name = $wpdb->prefix ."customer";
$result = $wpdb->get_results ( "SELECT * FROM $table_name where ID='$user_id' Order by ID desc" );
foreach ( $result as $print )  
{
           
        }
  $person = $print->person;
  $phone = $print->phone;
echo json_encode(array($person,$phone));
die();
 }

 add_action('wp_ajax_nopriv_get_single_use','get_single_use');
 add_action('wp_ajax_get_single_use','get_single_use');

No comments:

Post a Comment

How to create youtube videos slider with play and pause option in wordpress?

Create youtube videos slider with play and pause option in wordpress youtube videos slider Use this shortcode:- [punjab_today] function my_...