Twig/JqueryAjaxExtension.php
public function remoteCall($options = array())
    {
        return function ($options) {
            $type = isset($options['type']) ? $options['type'] : "POST";
            $dataType = isset($options['dataType']) ? $options['dataType'] : "html";
            $js = "$.ajax({
							url: '" . $options['url'] . "',
							type: '" . $type . "',
							dataType: '" . $dataType . "',";
            
            if (isset($options['before'])) {
                $before = str_replace('"', "'", $options['before']);
                $js .= "beforeSend: function(){" . $before . "},";
            }
            
            $js .= "success: function( data ){ $('" . $options['update'] . "').html(data);";
            
            if (isset($options['after'])) {
                $after = str_replace('"', "'", $options['after']);
                $js .= $after;
            }
            
            $js .= "}";
            
            if (isset($options['complete'])) {
                $complete = str_replace('"', "'", $options['complete']);
                $js .= ",complete: function(){" . $complete . "},";
            }
            
            $js .= "});";
            
            return $js;
        };
    }
public function remoteCall($options = array())
    {
        return function ($options) {
            $type = isset($options['type']) ? $options['type'] : "POST";
            $dataType = isset($options['dataType']) ? $options['dataType'] : "html";
            $js = "$.ajax({
							url: '" . $options['url'] . "',
							type: '" . $type . "',
							dataType: '" . $dataType . "',";
            
            if (isset($options['before'])) {
                $before = str_replace('"', "'", $options['before']);
                $js .= "beforeSend: function(){" . $before . "},";
            }
            
            $js .= "success: function( data ){ $('" . $options['update'] . "').html(data);";
            
            if (isset($options['after'])) {
                $after = str_replace('"', "'", $options['after']);
                $js .= $after;
            }
            
            $js .= "}";
            
            if (isset($options['complete'])) {
                $complete = str_replace('"', "'", $options['complete']);
                $js .= ",complete: function(){" . $complete . "},";
            }
            
            $js .= "});";
            
            return $js;
        };
    }
Generate Js function to send ajax request.

@param array $options