I’m using ajax in wordpress to get the output of a function:
jQuery.ajax({
type: "POST",
url:"wp-admin/admin-ajax.php",
data:'action=nafham_list_cats_selection&selection_id=' + $selection_id,
success:function(results){
jQuery(".semester_selection").empty();
jQuery(".semester_selection").prop('disabled', false);
jQuery(".semester_selection").append(results);
}
})
And here’s the function I use:
function nafham_list_cats_selection() {
if(isset($_POST['selection_id'])){
nafham_get_listed_cats($_POST['selection_id']);
die();
}
}
Using jQuery ajax I’m able to get the output of the function, but what I need to do is to get multiple outputs like if the function echos two variables, I’d like to be able to use the two values separated in the ajax response, is that possible?
Make an array of your output, for example if you have in your php file
Above code will send following json encoded string to the browser
in your ajax success callback function you can convert it to a json object using ‘parseJSON’
This is only an example and hope it’ll help you to understand. for more try this and this.