Ajax Class Efficiency So I wrote this class to handle my ajax calls simply:

ajaxCon.php:

class ajaxCon{
    private $init = false;
    private $functionArray = array();
    private $Message = false;
    private $function = null;
    private $arguments = null;
    private $post = null;

    public function __construct(){
        if(!isset($_POST['ajaxRequest'], $_POST['ajaxFunction'])) return;
        $this-&gt;init = true;
        ob_start();
        $this-&gt;post = $this-&gt;sanitizeArr($_POST);
        $this-&gt;arguments = $this-&gt;sanitizeArr($_POST['arguments']);
        $this-&gt;function = $_POST['ajaxFunction'];
    }

    public function addFunction($functionName, $functionCode){
        if(!$this-&gt;init || !isset($functionName, $functionCode) || $functionName != $this-&gt;function) return $this;
        $this-&gt;Message = call_user_func_array($functionCode, $this-&gt;arguments) ? 'success' : 'fail' ;
        unset($this-&gt;init, $this-&gt;functionArray, $this-&gt;post);
        $returnVars = get_object_vars($this);
        ob_clean();
        echo json_encode($returnVars);
        ob_flush();
        exit();
    }

    private function sanitizeArr($returnArr, $sanitizer = 'sanitize_sql_string') {
        array_walk_recursive($returnArr, function (&amp;$value) use ($sanitizer) {
            $value = $sanitizer($value);
        });

        return $returnArr;
    }
}


ajaxCon.js:

function ajax() {

    this.callback = false;

    this.ajaxFailure = function (returnData) {};

    this.ajaxSuccess = function (returnData) {};

    this.call = function(functionName, argumentArray, callback){
        $.ajax( $.extend(true, {}, this.ajaxSettings, {data:{'ajaxFunction':functionName, 'arguments':argumentArray}} ) );
        this.callback = callback;
    };

    this.ajaxReturn = function (returnData){
        returnData = returnData.substring(returnData.indexOf("{") - 1);
        returnData = returnData.substring(0, returnData.lastIndexOf("}") + 1);
        var responseArray = $.parseJSON(returnData);

        if (responseArray.Message.toLowerCase() != "success"){
            this.ajaxFailure(responseArray);
            return;
        }

        this.ajaxSuccess(responseArray);
        if(this.callback != false) this.callback(responseArray);
    };

    window.ajaxCon = this;
    this.ajaxSettings = { url: window.location.href, type: 'POST', cache: false, data: {ajaxRequest: true}, success: function (returnData) {
        ajaxCon.ajaxReturn(returnData)
    }};
}


and you call it like so:

&lt;?php
    $ajaxCon = new ajaxCon;

    $ajaxCon-&gt;addFunction('checkEmail', function($Email){
        global $ajaxCon;
        if(emailIsInDB($Email)) $ajaxCon-&gt;hasAccount = true;
        return true;
    });
?&gt;
&lt;script type="text/javascript"&gt;
    var ajaxCon = new ajaxCon();

    function checkEmail() {
        ajaxCon.call('checkEmail', {'Email':$('#Email').val()}, function(result){
            if(!result.hasAccount) $('#SignUp').submit();
        });
    }
&lt;/script&gt;


The drawbacks I know of are lot's of preprocessing (The entire page has to be preprocesed) and the page then executes as normal until the php function I need is defined and called.

Any ideas on how I can optimize the code and make it run more efficiently while preserving/improving readability?
A review of the JavaScript part:


ajaxCon is a class/constructor, so you should call it AjaxCon, though really I would think about finding an even better name :)
ajaxFailure -> You have a number of functions that have ajax in their name, since these functions are in the Ajax constructor you can drop the ajax part
this.callback = false; -> Don't declare callback at all and then use if(this.callback) this.callback(responseArray);
This could use some newlines:
$.ajax( $.extend(true, {}, this.ajaxSettings, {data:{'ajaxFunction':functionName, 'arguments':argumentArray}} ) );

and also 

this.ajaxSettings = { url: window.location.href, type: 'POST', cache: false, data: {ajaxRequest: true}, success: function (returnData) {
    ajaxCon.ajaxReturn(returnData)
}};

Also the location of this.ajaxSettings is odd, this belongs on top of that function