
/*
 * jQuery Deliver Reduced Extension
 * @author Ramon Lamana
 * @link http://www.rlamana.es
 *
 * @version 0.1 (24.Nov.2009)
 * @requires jQuery v1.3.1 or later
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

jQuery.fn.extend
({
    /**
     * Delivers a form via Ajax and POST method.
     *
     * @param {string} callback A function to be executed whenever the data is loaded successfully.
     * @example A callback function, like in jQuery ajax function:
     *	    function (data, text_status)
     *	    {
     *		// 'data' could be xmlDoc, jsonObj, html, text, etc...
     *		// textStatus can be one of:
     *		//	"timeout"
     *		//	"error"
     *		//	"notmodified"
     *		//	"success"
     *		//	"parsererror"
     *	    }
     *
     *	@param {string} data_type Type of data to be returned to callback function:
     *	    "xml", "html", "script", "json", "jsonp", or "text".
     *	@see jQuery.ajax()
     */
    deliver: function(callback, data_type)
    {
	// Para que no se envie el formulario
	$(this).submit(function(){return false;});

	// 'this' should be a form
	$.ajax
	({
		type:	'post',
		url:	$(this).attr('action'),
		data:	$(this).serialize(),
		success: function(response)
		{
		    callback.call(this, response, "success");
		},

		error: function(http_request, text_status, error_thrown)
		{
		    callback.call(this, {}, text_status);
		},
		dataType: data_type
	});
    }
});


