ajax multiple Values
i tryed to return multiple Values from an Ajax Call,
I would Like to retun Value a and value b in two separat Variables in my Ajax function.
Is it posible to do that? or could I use an Array? Or should i do for every Call a own Function?
My Function: "here i will do one ore more Database querys"
function rob_ajax_vorlage() {
global $wpdb;
$a = "100";
echo $a;
$b = "200"; //second value that doesen work jet
echo $b; //second value that doesen work jet
wp_die(); // just to be safe
}
add_action( 'wp_ajax_rob_ajax_vorlage_approal_action', 'rob_ajax_vorlage' );
add_action( 'wp_ajax_nopriv_rob_ajax_vorlage_approal_action', 'rob_ajax_vorlage' );
And my Ajax call
jQuery(document).ready(function($) {
$( '#rob-wp-ajax-vorlage-button' ).click( function() {
var abc = $( '#abc' ).val();
$.ajax({
method: "POST",
url: ajaxurl,
data: { 'action': 'rob_ajax_vorlage_approal_action', 'abc': abc, }
})
.done(function( data ) {
console.log('Successful AJAX Call! /// Return Data: ' + data);
.fail(function( data ) {
console.log('Failed AJAX Call :( /// Return Data: ' + data);
});
});
});
Im A Beginner so sorry if i asked something crazy.
so it would be grade if someone could help me to use return two values.
Thank you
Rob
Topic ajax plugin-development Wordpress
Category Web