Wordpress ajax returns JSON with php opening tag
<p>I'm creating an ajax registration in wordpress. I process the data sent from JS to PHP then send back a response using the code below.</p>

<pre><code>wp_send_json(array('success' =&gt; 'false', 'message' =&gt; __( 'Please select a user type.' )));
</code></pre>

<p>But the JSON response I get always starts with a php opening tag.</p>

<pre><code>&lt;?php{"success":"false","message":"Please select a user type."}
</code></pre>

<p>Can't find what's causing this.</p>

<p>Here's my php code</p>

<pre><code>&lt;?php

if ( !is_user_logged_in() ) {
    add_action( 'init', 'auth_init' );
}

function auth_init() {
    wp_enqueue_script( 'user-auth-js', get_stylesheet_directory_uri() . '/assets/js/user-auth.js', array(), false, true );

    add_action( 'wp_ajax_nopriv_ajax_registration', 'ajax_registration');
}

add_action( 'buddyboss_after_header', 'registration_modal' );
function registration_modal() {
    if ( !is_user_logged_in() &amp;&amp; !bp_is_register_page() ) {
        $bp = buddypress();

        if( empty( $bp-&gt;signup-&gt;step ) )
            $bp-&gt;signup-&gt;step='request-details';

        get_template_part( 'partials/content', 'registration-modal' );
    }
}

/**
 * Ajax Registration
 */
function ajax_registration(){

    check_ajax_referer( 'ajax-register-nonce', 'security' );

    $info = array();

    $info[ 'user_nicename' ]    = sanitize_user( $_POST[ 'username' ] );
    $info[ 'nickname' ]         = sanitize_user( $_POST[ 'username' ] );
    $info[ 'display_name' ]     = sanitize_user( $_POST[ 'username' ] );
    $info[ 'user_login' ]       = sanitize_user( $_POST[ 'username' ] );
    $info[ 'user_pass' ]        = sanitize_text_field( $_POST[ 'password' ] );
    $info[ 'user_email' ]       = sanitize_email( $_POST[ 'email' ] );

    // Checks if user type entered is valid
    if ( !$_POST[ 'user_type' ] ) {
        wp_send_json(array('success' =&gt; 'false', 'message' =&gt; __( 'Please select a user type.' )));
    }
    elseif ( sanitize_text_field( $_POST[ 'user_type' ] ) === 'client' ) {
        $info[ 'role' ] = 'client';
    }
    elseif ( sanitize_text_field( $_POST[ 'user_type' ] ) === 'vendor' ) {
        $info[ 'role' ] = 'vendor';
    }
    else {
        wp_send_json(array('success' =&gt; 'false', 'message' =&gt; __( 'Invalid user type selected.' )));
    }

    // Registers the user
    $user_register = wp_insert_user( $info );

    // Checks for errors returned
    if ( is_wp_error( $user_register ) ) {
        $error = $user_register-&gt;get_error_codes();

        if ( in_array( 'empty_user_login', $error ) ) {
            wp_send_json(array('success' =&gt; 'false', 'message' =&gt; __( $user_register-&gt;get_error_message( 'empty_user_login' ) )));
        }
        elseif ( in_array( 'existing_user_login', $error ) ) {
            wp_send_json(array('success' =&gt; 'false', 'message' =&gt; __( 'This username you entered is already registered.' )));
        }
        elseif ( in_array( 'existing_user_email', $error ) ) {
            wp_send_json(array('success' =&gt; 'false', 'message' =&gt; __( 'This email address you entered is already registered.' )));
        }
    }
}

/**
 * Log in user
 * @param  string $username Username
 * @param  string $password Password
 * @return boolean           [description]
 */
function auth_user_login( $username, $password ) {
    $info = array();
    $info[ 'user_login' ]       = $username;
    $info[ 'user_password' ]    = $password;
    $info[ 'remember' ]         = true;

    $user_signon = wp_signon( $info, false );
    if ( is_wp_error( $user_signon ) ) {
        return false;
    } else {
        wp_set_current_user( $user_signon-&gt;ID );
        return true;
    }
}
</code></pre>

<p>user-auth.js</p>

<pre><code>$(function () {

    $( '#signup_submit' ).click(function(e) {
        e.preventDefault();
        var btn = $( this ).button( 'loading' );

        var data = {
            action: "ajax_registration",
            user_type: $( 'input[name=signup_user_type]:checked', '#signup_form' ).val(),
            username: $( '#signup_username' ).val(),
            password: $( '#signup_password' ).val(),
            email: $( '#signup_email' ).val(),
            security: $( '#registration-security' ).val()
        };

        $.post( ajaxurl, data, function( response ) {
            console.log( response );
            btn.button( 'reset' );
        } );

    });


});
</code></pre>