js-identifiers/script.js

$(function()
{
	$('#form').submit(doSubmit);
	$('#output').hide();
});

function doSubmit(event)
{
	var form = $(this);
	if(form.attr('method') == 'post')
		$.post(form.attr('action'), form.serializeObject(), onReturn);
	else
		$.get(form.attr('action'), form.serializeObject(), onReturn);

	return false;
}

function onReturn(data)
{
	$('#output')
		.empty()
		.hide()
		.append(data)
		.slideDown();
}


/**
 * Serializes a form into an object.
 */
$.fn.serializeObject = function()
{
	var o = {};
	var a = this.serializeArray();
	$.each(a, function() {
		if (o[this.name]) {
			if (!o[this.name].push) {
				o[this.name] = [o[this.name]];
			}
			o[this.name].push(this.value || '');
		} else {
			o[this.name] = this.value || '';
		}
	});
	return o;
};