0
        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);
            }
        })

This is the ajax call I'ms ending, the following is the function that sends the data:

function nafham_list_cats_selection() {
    if(isset($_POST['selection_id'])){ 
        nafham_get_listed_cats($_POST['selection_id']);

    }
}

How can I let the function outputs two values so that I can use

success:function(results1, results2){
2

Instead of passing two parameters to function you can pass the array of two values like this :

$results['args1'] = "value1";
$results['args2'] = "value2";

echo json_encode($results);

and then get it in success function like this :

success:function(results){
jQuery(".semester_selection1").append(results.args1); // This appends value1
jQuery(".semester_selection2").append(results.args2); // This appends value2
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.