Hi there,
I and trying to create cascading dynamically loading dropdownlist in a custom wordpress plugin and cannot seem to get it working. Please see code below, any help would be greatly appreciated.

the console just returns "undefined", i am not sure if it is even running the php function?

here is the code:

jQuery Code in a separare js/scripts.js file.
Code:
jQuery(document).ready(function() {
jQuery('#ddlSchool').change(function(){
var school=jQuery('#ddlSchool').val();
jQuery('#ddlResVisit').empty(); //remove all existing options
jQuery.ajax({
			type: 'POST',
			dataType: 'json',
			url: residential_visits.ajaxurl,
			data: {
				'action' : 'residential_visits',
				'school' : school
			},
			complete: function( object ) {
				console.log(object.responseJSON.body );
				alert(object.responseJSON.body);
				//if get correct data then deal with dropdownlist
			}
		});
		});
			});
In my plugin php file:
Code:
//Register and Enqueue my scripts
wp_register_script('ajax-script', plugins_url('js/jsscripts.js', __FILE__), array('jquery'),'1.1');
wp_enqueue_script('ajax-script');

//localise the wordpress ajax file
wp_localize_script( 'ajax-script', 'residential_visits', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );

 // add the ajax actions for bothj logged in and non logged in users
add_action( 'wp_ajax_residential_visits', 'residential_visits');
add_action( 'wp_ajax_nopriv_residential_visits', 'residential_visits');

function residential_visits() {
    // Handle request then generate response using WP_Ajax_Response
$school = $_POST['ddlSchool'];
global $wpdb;
//SQL will have query at end school='$school'
$result = get_results("select id, group_name from wp_pods_residential_visits");

$main = array('data'=>$result);
echo json_encode($result); //return the data back.

// stop execution afterward.
wp_die();
}
Drop down CODE:
Code:
global $wpdb;
		  $schools = $wpdb->get_results("Select abbr_code, school_name from wp_pods_schools order by school_name;");
		  ?>
	      <label for"ddlSchools">School Attending:</label>
	      <select name="ddlSchool" id="ddlSchool">
	        <?php
			  foreach ($schools as $school){
				  ?>
	        <option value="<?php echo $school->abbr_code ?>"><?php echo $school->school_name ?></option>
	        <?php
			  }
			  ?>
          </select>
	   <!-- Dropdown to be populated based upon previous selection. -->
   <select id="ddlResVisit" name="ddlResVisit">
          </select>
thanks