Twig/JqueryAjaxExtension.php
public function submitCall($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 . "',
		    		data: $(this.form.elements).serializeArray(),
		    		dataType: '" . $dataType . "',";
    		if (isset($options['before'])) {
    			$before = str_replace('"', "'", $options['before']);
    			$js .= "beforeSend: function(){" . $before . "},";
    		}
    		$js .= "success: function( data ){";
    		if (isset($options['success'])) {
    			$success = str_replace('"', "'", $options['success']);
    			$js .= $success ;
    		}
    		if (isset($options['after'])) {
    			$after = str_replace('"', "'", $options['after']);
    			$js .= $after;
    		}
    
    		$js .= "}});";
    
    		return $js;
    	};
    }
public function submitCall($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 . "',
		    		data: $(this.form.elements).serializeArray(),
		    		dataType: '" . $dataType . "',";
    		if (isset($options['before'])) {
    			$before = str_replace('"', "'", $options['before']);
    			$js .= "beforeSend: function(){" . $before . "},";
    		}
    		$js .= "success: function( data ){";
    		if (isset($options['success'])) {
    			$success = str_replace('"', "'", $options['success']);
    			$js .= $success ;
    		}
    		if (isset($options['after'])) {
    			$after = str_replace('"', "'", $options['after']);
    			$js .= $after;
    		}
    
    		$js .= "}});";
    
    		return $js;
    	};
    }
Generate Js function to send ajax form data.

@param array $options