Skip to main content

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');

Comments

Popular posts from this blog

How to check date format in PHP?

Check date format in PHP function isCorrectDateFromat($date){     if(!empty($date)){         $dateString = $date; // Replace this with your date string         $format = "Y-m-d"; // Replace this with your expected date format         $dateTime = DateTime::createFromFormat($format, $dateString);         if ($dateTime === false) { /*             echo "The date is not in the correct format."; */         } else {             $errors = DateTime::getLastErrors();             if (empty($errors)) { /*                 echo "The date is in the correct format."; */                 return true;             } else { /*                 echo "...