AJAX not returning in Wordpress

I am trying to make an AJAX Call in Wordpress and I am not having any luck.  The console shows all of the returns but they are not being printed out on the page.
jQuery(document).ready(function($) {

	// Listen for a click event on our text input submit button
	$( '.wcsf-submit-field' ).click( function( e ) {

		// Stop the button from submitting and refreshing the page.

		// Now that a click has happened, let's run Ajax!!!!!!!!!
			type: 'POST',
			dataType: 'json',
			url: wcsf_ajax.ajaxurl,
			data: {
				'action' : 'wcsf_ajax',
				//'data' : $( '.wcsf-text-field' ).val(),
				//'submission' : $( '.wcsf-submitted' ).val(),
				//'nonce' : $( '#wcsf-nonce' ).val(),
			success: function( data ) {
				$( '#load_returns' ).html(data);


class WCSF_Example {

     * The construct method. This is where we hook all of our scripts outlined below.
    public function __construct() {
        // Enqueue our ajax with WordPress
        add_action('wp_enqueue_scripts', array($this, 'add_javascript'));
        // Hook our Ajax script with the action we specified in the ajax request
        add_action('wp_ajax_wcsf_ajax', array($this, 'wcsf_ajax'));
        // Add our input/button at the end of the_content() function
        add_filter('the_content', array($this, 'add_button'));

     * Enqueue our JavaScriptssssss
    public function add_javascript() {
        // Enqueue our jQuery. You never know if an install is loading it!
        // Call our script that contains the Ajaxy goodness.
        wp_enqueue_script('wcsf_exmaple_ajax', plugins_url('js/ajax.js', __FILE__));
        // Although used for translation, this function allows us to load arbitrary JS built with PHP into the head of our WP theme
        // Without modifying the themes header.php :) #magix
        // We only need the admin ajax file in WordPress, so that's all we'll do.
        wp_localize_script('wcsf_exmaple_ajax', 'wcsf_ajax', array(
            'ajaxurl' => admin_url('admin-ajax.php'),

     * The actual script to process the Ajax request.
     * This function is called when we pass the "action" key through $_POST and WordPress will map that to the proper add_action().
     * We'll process and then return the data in JSON form. Make sure you sanitize yo data! Safty first.
    public function wcsf_ajax() {
        // Check that we requested this from the input field and the nonce is valid. Prevents malicious users.
        //if (!isset($_POST['submission']) && !$_POST['submission'] && !wp_verify_nonce($_POST['nonce'], 'wcsf-ajax'))
                     global $wpdb;
header('Content-Type: application/json');
        $get_id = $wpdb->get_results('SELECT term_id AS id, name AS name FROM wp_connections_terms WHERE term_id != 1');
        foreach ($get_id as $row) {
            $name = $row->name;
            $id = $row->id;

            $taxid = $wpdb->get_results("
          SELECT wp_connections_meta.meta_value AS value 
          FROM wp_connections_term_relationships, wp_connections_meta 
          WHERE wp_connections_term_relationships.term_taxonomy_id = '$id' AND (wp_connections_term_relationships.entry_id = wp_connections_meta.entry_id)"

            $value = array();
            foreach ($taxid as $row) {
                $val = $row->value;
                $value[] = $val;
            echo 'Sales Manager: ' . $name . '&nbsp;&nbsp;$' . array_sum($value) . '<br /><br />';
         $data = ob_get_clean();  

     * Add our input/button at the end of the_content() function
    public function add_button() {
        echo '<form id="wcsf-example">';
        echo '<input type="text" class="wcsf-text-field" placeholder="Add your text" value="">';
        echo '<input type="submit" class="wcsf-submit-field" value="Add yo text!" />';
        echo '<input type="hidden" name="wcsf-submitted" class="wcsf-submitted" value="true" />';
        wp_nonce_field('wcsf-ajax', 'wcsf-nonce'); // Adds our nonce and creates a unique key automatically! #moremagix
        echo '</form>';


// Initiate our class.
$wcsf_example = New WCSF_Example();

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Leonidas DosasCommented:
How the php code is triggered?I mean I cant see any if isset $_POST['action']

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rgranlundAuthor Commented:
I actually figured it out.  I forgot to us ob_start so it ws not looping the way WP wants it to.  Thanks!
rgranlundAuthor Commented:
Thanks for your help.  I got what I needed.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.