Tag Archive for ajax

HTML Hello World

<html>
<head>
<title>Titel der Webseite</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<style type="text/css">
body {background-color: white}
table.sample{
padding: 2px 4px 2px 4px;
border: 1px solid ;
}
</style>

</head>
<body>
Inhalt der Webseite
</body>
</html>

source

JavaScript Hello Workd

<html>
<head>
<title>Titel der Webseite</title>
<!-- Evtl. weitere Kopfinformationen -->
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript">
function doSomething(){
alert(document.getElementById("foo").value);
alert($("#foo").val());
}
</script>
</head>
<body onload="doSomething()">

Inhalt der Webseite
<input type="text" id="foo" />
<input type="button" name="Text 1" value="Text 1 anzeigen" onclick="doSomething()">
</body>
</html>

source

AJAX XSS Proxy Script

<?php

/*
By:		Matt Ford

Purpose:	This is a PHP powered proxy script for XSS scripting
*/

class phpProxy {
public	$url 		= null; //request url
public	$headers 	= null; //boolean headers
public	$mimeType 	= null; //mimetype of response

private	$session 	= null; //curl session
public	$response 	= null; //curl response

public function __construct($request) {
$this->phpProxy($request);
}

public function phpProxy($request) {
$this->url = trim($request["url"]);
$this->headers = trim($request["headers"]);
$this->mimeType = trim($request["mimeType"]);

if ($this->url != "") {
$this->initRequest();
}
else {
$this->response = null;
}
}

private function initRequest() {
$this->session = curl_init($this->url);

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$postVars = array();;

foreach ($_POST as $k => $v) {
$postVars[] = $k . "=" . $v;
}

$postVars = implode("&", $postVars);

curl_setopt ($this->session, CURLOPT_POST, true);
curl_setopt ($this->session, CURLOPT_POSTFIELDS, $postVars);
} else {}

curl_setopt($this->session, CURLOPT_HEADER, ($this->headers == "true") ? true : false);
curl_setopt($this->session, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($this->session, CURLOPT_RETURNTRANSFER, true);

$this->response = curl_exec($this->session);

if ($this->mimeType != "") {
header("Content-Type: " . $this->mimeType);
} else {}

//echo $this->response;
curl_close($this->session);
}
}

$phpProxy = new phpProxy($_REQUEST);
?>

source

ImgX Controls / ASP.NET AJAX Demo Page with Scanning, Upload and Thumbnail generation.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
public bool ThumbnailCallback()
{
return false;
}

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
string id = Request.Params["id"];

if (!string.IsNullOrEmpty(id) && Session[id] as byte[] != null)
{
byte[] thumbnailBytes = null;

/*
* Microsoft Support: Bitmap and Image constructor dependencies (http://support.microsoft.com/Default.aspx?id=814675)
* Google: "A generic error occurred in GDI+." 2147467259 (http://www.google.gr/search?num=100&hl=en&q=%22A+generic+error+occurred+in+GDI%2B.%22+2147467259)
* In sort, we must keep the originating stream of an Image as long as we want to do computations with that image.
*/

using (System.IO.MemoryStream msImage = new System.IO.MemoryStream(Session[id] as byte[]))
{
System.Drawing.Image image = System.Drawing.Image.FromStream(msImage);

using (System.IO.MemoryStream msThumbnail = new System.IO.MemoryStream())
{
System.Drawing.Image.GetThumbnailImageAbort myCallback =
new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);

int factor = 10;
try
{
factor = Int32.Parse(Request.Params["factor"]);
}
catch
{
// Ignore.
}

System.Drawing.Image thumbnail = image.GetThumbnailImage(image.Width / factor, image.Height / factor, null, IntPtr.Zero);
thumbnail.Save(msThumbnail, System.Drawing.Imaging.ImageFormat.Jpeg);
thumbnailBytes = new byte[msThumbnail.Length];

msThumbnail.Seek(0, System.IO.SeekOrigin.Begin);
msThumbnail.Read(thumbnailBytes, 0, thumbnailBytes.Length);
}
}

Response.ContentType = "image/jpeg";
Response.BinaryWrite(thumbnailBytes);
}
}

[System.Web.Services.WebMethod]
public static string Upload(string encodedImage)
{
if (string.IsNullOrEmpty(encodedImage))
throw new ArgumentException(string.Empty, "encodedImage");

string id = (new Random()).Next().ToString();
HttpContext.Current.Session[id] = System.Convert.FromBase64String(encodedImage);

return id;
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>

<script type="text/javascript">
function ButtonFirst_Click(evt) {
evt.preventDefault();

var imgx = $get('ImgX');
imgx.Images.Current = imgx.Images(0);

UpdateView();
}

function ButtonPrevious_Click(evt) {
evt.preventDefault();

var imgx = $get('ImgX');
imgx.Images.Current = imgx.Images(imgx.Images.Current.Index - 1);

UpdateView();
}

function ButtonNext_Click(evt) {
evt.preventDefault();

var imgx = $get('ImgX');
imgx.Images.Current = imgx.Images(imgx.Images.Current.Index + 1);

UpdateView();
}

function ButtonLast_Click(evt) {
evt.preventDefault();

var imgx = $get('ImgX');
imgx.Images.Current = imgx.Images(imgx.Images.Count - 1);

UpdateView();
}

function pageLoad(sender, e) {
// Attach event handlers.
$addHandler($get('<%= ButtonScan.ClientID %>'), 'click', ButtonScan_Click);
$addHandler($get('<%= Slider1.ClientID %>'), 'change', Slider1_Change);
$addHandler($get('<%= ButtonUpdateThumbnail.ClientID %>'), 'click', ButtonUpdateThumbnail_Click);
$addHandler($get('<%= ButtonFirst.ClientID %>'), 'click', ButtonFirst_Click);
$addHandler($get('<%= ButtonPrevious.ClientID %>'), 'click', ButtonPrevious_Click);
$addHandler($get('<%= ButtonNext.ClientID %>'), 'click', ButtonNext_Click);
$addHandler($get('<%= ButtonLast.ClientID %>'), 'click', ButtonLast_Click);
$get('ImgXTwain').attachEvent('ImageAcquired', ImgXTwain_ImageAcquired);

// ImgX initialization.
var imgx = $get('ImgX');
imgx.AutoZoomType = 1;

UpdateView();
}
function Slider1_Change(evt) {
$get('ImgX').Zoom = evt.target.value / 100;
}

function ButtonUpdateThumbnail_Click(evt) {
evt.preventDefault();
var imgx = $get('ImgX');

var imageType = 1; // enum value for jpeg

if (imgx.Images.Count > 1) {
imageType = 3; // enum value for Tiffs
imgx.ImgX.TIFCompression = 4; // Set packbits compression for 8, 24, 32 bit images.
}

// Get a base64 string representing our encoded image.
var tempElement = (new ActiveXObject("Microsoft.XMLDOM")).createElement("tempElement");
tempElement.dataType = "bin.base64";
tempElement.nodeTypedValue = imgx.Export.ToMemoryFileVariant(imageType);

// Upload
PageMethods.Upload(tempElement.text, Upload_Success);
}

function Upload_Success(result, context, methodName) {
var img = $get('<%=Image1.ClientID %>');
img.src = '?id=' + result;
}

function ButtonScan_Click(evt) {
evt.preventDefault();
$get('ImgXTwain').Acquire(false, theForm.ImgX.hWnd);
}

function ImgXTwain_ImageAcquired(image) {

var imgx = $get('ImgX');

// Set scanning options. These must be set before image acquisition.
imgx.AutoZoom = $get('<%=CheckBoxAutoZoom.ClientID %>').checked;
imgx.AutoCrop = $get('<%=CheckBoxAutoCrop.ClientID %>').checked;
imgx.Images.Add(theForm.ImgX.Support.GetImageFromVariant(image), 0, false);

UpdateView();
}

function UpdateView() {
var imgx = $get('ImgX');

$get('<%=ButtonUpdateThumbnail.ClientID %>').disabled = imgx.Images.Count == 0;

if (imgx.Images.Count < 2) {
$get('<%=ButtonPrevious.ClientID %>').disabled =
$get('<%=ButtonFirst.ClientID %>').disabled =
$get('<%=ButtonLast.ClientID %>').disabled =
$get('<%=ButtonNext.ClientID %>').disabled = true;
}
else {
$get('<%=ButtonPrevious.ClientID %>').disabled =
$get('<%=ButtonFirst.ClientID %>').disabled = imgx.Images.Current.Index == 0;
$get('<%=ButtonLast.ClientID %>').disabled =
$get('<%=ButtonNext.ClientID %>').disabled = imgx.Images.Count == imgx.Images.Current.Index + 1;
}

if (imgx.Images.Count > 0) {
$get('SpanCurrent').innerHTML = imgx.Images.Current.Index + 1;
$get('SpanCount').innerHTML = imgx.Images.Count;
}
else {
$get('SpanCurrent').innerHTML = $get('SpanCount').innerHTML = 0;
}

$find("<%=SliderExtender1.ClientID%>").set_Value(Math.round(imgx.Zoom * 100));
}
</script>

<div>
<div style="display: none">
<object id="ImgXTwain" classid="CLSID:354D91A8-E3C9-491F-BB89-0FB27DEEED86">
</object>
</div>
<div style="float: left; position: relative; top: 25px; margin: 5px;">
<ajaxToolKit:SliderExtender ID="SliderExtender1" runat="server" TargetControlID="Slider1"
Minimum="1" RaiseChangeOnlyOnMouseUp="false" Orientation="Vertical" BoundControlID="Slider1_BoundControl">
</ajaxToolKit:SliderExtender>
<asp:TextBox ID="Slider1" runat="server"></asp:TextBox>
<asp:Label ID="Slider1_BoundControl" runat="server"></asp:Label>%
</div>
<div style="float: left">
<asp:Panel ID="Panel3" runat="server" Style="text-align: center;">
<asp:Button ID="ButtonFirst" runat="server" Text="<< First" />
<asp:Button ID="ButtonPrevious" runat="server" Text="< Previous" />
<span id="SpanCurrent"></span>&nbsp;of&nbsp;<span id="SpanCount"></span>
<asp:Button ID="ButtonNext" runat="server" Text="Next >" />
<asp:Button ID="ButtonLast" runat="server" Text="Last >>" />
</asp:Panel>
<object id="ImgX" classid="clsid:111A5E7A-EAAC-433A-B56B-0AF470BE6306" style="width: 353px;
height: 500px;">
<param name="BackColor" value="16777215" />
<param name="MouseTool" value="2" />
<param name="AntialiasDisplay" value="True" />
<param name="Center" value="True" />
<param name="UndoLevels" value="3" />
</object>
</div>
<div style="float: left; width: 400px; margin-left: 10px">
<asp:Panel ID="Panel1" runat="server" GroupingText="Scan">
<asp:Button ID="ButtonScan" runat="server" Text="Scan" Style="float: right" />
<asp:CheckBox ID="CheckBoxAutoZoom" runat="server" Text="AutoZoom" Checked="true" />
<asp:CheckBox ID="CheckBoxAutoCrop" runat="server" Text="AutoCrop" Checked="true" />
</asp:Panel>
<asp:Panel ID="Panel2" runat="server" GroupingText="Thumbnail">
<asp:Button ID="ButtonUpdateThumbnail" runat="server" Text="Update" Style="float: right" />
<asp:Image ID="Image1" runat="server" />
</asp:Panel>
<asp:Panel ID="Panel5" runat="server" GroupingText="Edit">
<asp:Button ID="ButtonRemove" runat="server" Text="Remove" ToolTip="Remove image from collection" />
</asp:Panel>
</div>
</div>
</form>
</body>
</html>

source

Pass dynamic javascript parameters with ajax call

remote_function(
:url => {:controller => 'testing', :action => "test"}
:with => "'value=' + function_call()"
)

source

submitEvents – Javascript form submission handler

//
// submitEvent 0.2
// 19/08/2008
//
// Version History:
//
// 0.2
//   Slightly better fix, using .bind(this) instead of a temporary
// window.submitFormData var
//
// 0.11
//   Hacky fix for IE6
//
// 0.1
//   Initial release
//
//
// A small class for easily implementing many submit events including
// displaying a confirmation dialog, disabling the submit button and
// displaying an informative div so that the users stay informed.
//
// Please see example.html for some examples
//
// All the options are detailed below, and the defaults can be easily
// changed to suit your needs.
//
// Requires mootools 1.2 (I don't think it'll work with lower) although
// I may also make a prototype/scriptaculous version if required.
//
// This software is released under the Creative Commons Share Alike
// license.
//
// Dom
//
// <a href="http://www.dom111.co.uk/" >http://www.dom111.co.uk/</a>
//
var submitEvent = new Class({
Implements: [Options],

// options
//
// the default options
// these can be overridden here if you use the same
// settings often, to save yourself time
//
options: {
// confirmation
//
//  enabled: boolean
//  text: text to display on said dialog box
//  confirmed: used internally to make sure the
// confirmation isn't displayed again if there's a
// timeout
confirmation: {
enabled: false,
text: 'Are you sure?',
confirmed: false
},
// submitButton
//
//  object: the object (or id as string) that is the
// primary submit button for f
//  changeText: whether or not to change the button's
// text on submit
//  newText: text to change the button to
//
submitButton: {
object: null,
disable: true,
changeText: true,
text: 'Please wait...'
},
// informationDiv
//
//  display: whether or not to diplay an information
// div
//  className: CSS class to apply to the div
//  centered: whether to horizontally center the div
// (uses left: xxpx so class must add position absolute)
//  text: text (or HTML to populate the div with
//  inject: element to inject the div into (this.form
// is used if this is left as null/false)
//  injectTo: position to inject element to eg. bottom,
// top, before, after defaults to after
//
informationDiv: {
enabled: true,
className: '',
centered: true,
text: 'Loading...',
inject: null,
injectTo: 'after'
},
//
// undo
//  enabled: boolean
//  timeout: in seconds to run specified undo tasks
//
// submitButton:
//  enabled: re-enable the submit button
//  newText: text to display on the newly enabled
// submit button
//
// informationDiv
//  text: updated text to display
//  className: updated CSS class to apply
undo: {
enabled: true,
timeOut: 30,
submitButton: {
enabled: true,
newText: 'Try Again'
},
informationDiv: {
enabled: true,
text: 'Sorry, there was a problem.',
className: ''
}
},
//
// ajax
//
// makes the form submission use ajax
//
//  enabled: boolean
//  update: the dom node, or a string id of the element
// to update, if not set, defaults to this.form
//  appendUrl: a query string to append to the ajax request
// (could be used to surpress header/footer or just distinguish
// between ajax/normal requests)
//
ajax: {
enabled: false,
udpate: null,
appendUrl: 'ajax=1'
}
},

initialize: function(f, o) {
// if f is a string, look for that element id...
if ($type(f) == 'string') {
f = $(f);
}

// if f still isn't an object, give up...
if ($type(f) != 'object' && $type(f) != 'element') {
return true;  // ... and submit the form, because we can't do anything...
}

// store the form object as this.form
this.form = f;

// save the old onsubmit function
this.preservedOnSubmit = this.form.onsubmit || function() {};

// merge the options...
this.setOptions(o || {});
if (!(this.options.submitButton.object)) {
this.options.submitButton.object = this.findSubmitButton(this.form);
if (!(this.options.submitButton.object.id)) {
this.options.submitButton.object.id = 'submitEventSubmitButton_' + new Date().getTime();
}
}

this.options.submitButton.oldText = this.options.submitButton.object.value;

this.informationDiv = false;
this.submitButtonFunctionTimeout = false;
this.informationDivFunctionTimeout = false;
},

// process
//
// do the magic!
process: function() {
// carry out functions in order:
//
// check for a confirmation message first, as if the user
// wants to cancel we could save ourselves some time
if ((this.options.confirmation.enabled) && !(this.options.confirmation.confirmed)) {
// if the text is blank or it's not a string
if (!(this.options.confirmation.text) || $type(this.options.confirmation.text) != 'string') {
// set it to some default text
this.options.confirmation.text = 'Are you sure?'
}
// set c to true/false from the user box
var c = confirm(this.options.confirmation.text);

// if it's true
if (c) {
// set the confirmed variable to true so the dialog isn't displayed again
this.options.confirmation.confirmed = true;
} else {
// else stop processing anything
return false;
}
}

// next, change the submit button if required
if ((this.options.submitButton.changeText) || (this.options.submitButton.disable)) {
// if the object, isn't an object, make it one
if ($type(this.options.submitButton.object) == 'string') {
this.options.submitButton.object = $(this.options.submitButton.object);
}

// create a variable for the button, of the object
var button = this.options.submitButton.object;

// make sure it's not null or false
if (button) {

// if we're supposed to change the text, do...
if (this.options.submitButton.changeText) {
button.value = this.options.submitButton.text || 'Please wait...';
}

// if we're supposed to disable it, do!
if (this.options.submitButton.disable) {
button.disabled = true;
}
}
}

// information div... display if required
if ((this.informationDiv) || (this.options.informationDiv.enabled)) {
if ((this.options.informationDiv.text) && $type(this.options.informationDiv.text) == 'string') {
// check the text is a string and nothing else
if (!this.informationDiv) {
// create a div element
this.informationDiv = new Element('div', {
'id': 'submitEventInformationDiv_' + new Date().getTime()
});

} else {
if (this.options.undo.informationDiv.className) {
this.informationDiv.removeClass(this.options.undo.informationDiv.className);
}
}

// set the innerHTML to the specified 'text', or default
this.informationDiv.set('html', this.options.informationDiv.text || 'Loading...');
// add the className if set
this.informationDiv.addClass(this.options.informationDiv.className || '')
// inject the element into the specified element, or this.form if not specified
this.informationDiv.inject(this.options.informationDiv.inject || this.form, this.options.informationDiv.injectTo || 'after');

if (this.options.informationDiv.centered) {
this.informationDiv.setStyle('left', this.getCenter(this.informationDiv) + 'px');
}
}
}

// undo, the best bit...
//
// if we can run undo tasks and at least one is enabled...
if (this.options.undo.enabled && (this.options.undo.submitButton.enabled || this.options.undo.informationDiv.enabled)) {
// set the timeout variable to seconds * 1000 (milliseconds)
var timeOut = (this.options.undo.timeOut || 30) * 1000;

// if we can run the undo on the button
if (this.options.undo.submitButton.enabled) {
// build the function to re-enable it and change the text
submitButtonFunction = function() {
var button = this.options.submitButton.object;
button.disabled = false;
button.value = this.options.undo.submitButton.newText || this.options.submitButton.oldText;
}
// use mootools timeout function, which allows this to be used
this.submitButtonFunctionTimeout = submitButtonFunction.delay(timeOut, this);
}

// if we can do the same magic with the information div...
if (this.options.undo.informationDiv.enabled) {

// build a function to change the text
informationDivFunction = function() {
if (this.options.undo.informationDiv.text) {
this.informationDiv.set('html', this.options.undo.informationDiv.text || 'Sorry, there was a problem.');
}

// and add the new class
if (this.options.undo.informationDiv.className) {
this.informationDiv.removeClass(this.options.informationDiv.className || '');
this.informationDiv.addClass(this.options.undo.informationDiv.className);
}

if (this.options.informationDiv.centered) {
this.informationDiv.set('styles', {
'left': this.getCenter(this.informationDiv) + 'px'
})
}
}

// another lovely timeout function
this.informationDivFunctionTimeout = informationDivFunction.delay(timeOut, this);
}
}

// if we're ajaxing it up...
if (this.options.ajax.enabled) {
// create a mootools request object
this.ajaxRequest = new Request.HTML({
// populate it with all the details from the HTML form
method: this.form.method,
url: this.appendQueryString(this.form.action),
// data: this.form.toQueryString(), // fails in IE 6?
data: this.formToQueryString(this.form),
update: this.options.ajax.update || this.form,
// add an oncomplete function to remove the additions
onComplete: function() {
$clear(this.submitButtonFunctionTimeout);
$clear(this.informationDivFunctionTimeout);
if ($(this.informationDiv.id)) {
$(this.informationDiv.id).destroy();
}
if ($(this.options.submitButton.object.id)) {
$(this.options.submitButton.object.id).value = this.options.submitButton.oldText;
$(this.options.submitButton.object.id).disabled = false;
}
}.bind(this)
}).send();

// make sure the main form isn't submitted
return false;
} else {
return true;  // post the form
}
},

// findSubmitButton
//
// returns the first submit button on a form
//
findSubmitButton: function(f) {
// if f fails use document
f = f || document;
// loop through all input elements in f
var i = f.getElementsByTagName('input');
for (var x = i.length - 1; x >= 0; x--) {
if (i[x].type == 'submit' || i[x].type == 'image') {
return i[x];
}
}
// loop through all button elements in f
var i = f.getElementsByTagName('button');
for (var x = i.length - 1; x >= 0; x--) {
if (i[x].type == 'submit') {
return i[x];
}
}
// we didn't find anything, so return null
return null;
},

// getCenter
//
// returns the width of the screen / 2 or the width
// of the screen - el.width / 2 for centering elements
//
getCenter: function(el) {
// w contains w.x and w.y
var w = window.getSize();

// if el is a string, make it an element
if ($type(el) == 'string') {
el = $(el);
}

// if el is all working
if (el) {
// get the sizes of it
var e = el.getSize();

// return the screen size minus the elements width / 2
return (w.x - e.x) / 2;

} else {
// just return the screen size / 2
return w.x / 2;
}
},

// appendQueryString
//
// returns the url with the extra query string correctly
// appended
//
appendQueryString: function(u) {
if (q = this.options.ajax.appendUrl) {
return (u.match(/?/)) ? u + '&' + q : u + '?' + q;
} else {
return u;
}
},

// formToQueryString
//
// Ripped and modified from mooTools as form.toObject() was failing.
//
formToQueryString: function(form) {
var obj = {};

var inputs = form.getElementsByTagName('input');
var selects = form.getElementsByTagName('select');
var textareas = form.getElementsByTagName('textarea');

var els = [];
els[els.length] = inputs;
els[els.length] = selects;
els[els.length] = textareas;

for (var i = 0; i < els.length; i++) {
for (var j = 0; j < els[i].length; j++) {
var name = els[i][j].name;
var value = els[i][j].value;
if ((value !== false) && name) obj[name] = value;
}
}

var s = '';

$each(obj, function(value, name) {
s += name + '=' + value + '&';
});

return s;
}

});

Examples:

<?php
if (!empty($_POST)) {
sleep(5);
var_dump($_POST);
die();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>submitEvents</title>

<script src="/js/mootools1.2.js" type="text/javascript" charset="utf-8"></script>
<script src="/js/submitEvent.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<form action="examples.php" method="post" onsubmit="return new submitEvent(this).process();">
<p>This form is using the default options</p>
<p><input type="text" name="name" value="" id="name"/></p>
<p><input type="text" name="email" value="" id="email"/></p>
<p><input type="submit" name="submitButton" value="Submit"/></p>
</form>

<form action="examples.php" method="post" onsubmit="return new submitEvent(this, { ajax: { enabled: true, update: $('test1') }, undo: { timeOut: 3 } } ).process();">
<p>This form is using the default options with ajax (and a very low undo wait, to test the return to normality...)</p>
<p><input type="text" name="name" value="" id="name"/></p>
<p><input type="text" name="email" value="" id="email"/></p>
<p><input type="submit" name="submitButton" value="Submit"/></p>
</form>
<div id="test1"></div>

<form action="examples.php" method="post" onsubmit="return new submitEvent(this, { confirmation: { enabled: true, text: 'Sure you're ready to submit?' } } ).process();">
<p>This form is using the default options with a confirmation dialog</p>
<p><input type="text" name="name" value="" id="name"/></p>
<p><input type="text" name="email" value="" id="email"/></p>
<p><input type="submit" name="submitButton" value="Submit"/></p>
</form>

<form action="examples.php" method="post" onsubmit="return new submitEvent(this, { confirmation: { enabled: false }, ajax: { enabled: false }, informationDiv: { enabled: false } } ).process();">
<p>This form is only going to disable the submit button</p>
<p><input type="text" name="name" value="" id="name"/></p>
<p><input type="text" name="email" value="" id="email"/></p>
<p><input type="submit" name="submitButton" value="Submit"/></p>
</form>

<form action="examples.php" method="post" id="totallyJavascriptForm">
<p>This form is using the default options, but specified directly, and the event is added via javascript</p>
<p><input type="text" name="name" value="" id="name"/></p>
<p><input type="text" name="email" value="" id="email"/></p>
<p><input type="submit" name="submitButton" value="Submit"/></p>
</form>

<script type="text/javascript" charset="utf-8">
$('totallyJavascriptForm').addEvent('submit', function() {
return new submitEvent(this, {
confirmation: {
confirmation: {
enabled: false,
text: 'Are you sure?',
confirmed: false
},
submitButton: {
object: null,
disable: true,
changeText: true,
text: 'Please wait...'
},
informationDiv: {
enabled: true,
className: '',
centered: true,
text: 'Loading...',
inject: null,
injectTo: 'after'
},
undo: {
enabled: true,
timeOut: 30,
submitButton: {
enabled: true,
newText: 'Try Again'
},
informationDiv: {
enabled: true,
text: 'Sorry, there was a problem.',
className: ''
}
},
ajax: {
enabled: false,
udpate: null,
appendUrl: 'ajax=1'
}
}
}).process()
});
</script>

</body>
</html>

source

Create XMLHttpRequest

function createXMLHttpRequestObject() {
var resObject = null;

try {
resObject = new ActiveXObject("Mircosoft.XMLHTTP");
window.console.log("Microsoft.XMLHTTP");
}

catch (error) {
try {
resObject = new ActiveXObject("MSXML2.XMLHTTP")
window.console.log("MSXML2.XMLHTTP");
}
catch(error) {
try {
resObject = new XMLHttpRequest();
window.console.log("XMLHttpRequest");
}
catch (error) {
alert("XMLHttpRequest-Objekt konnte nicht erzeugt werden.");
}
}
}

return resObject;
}

source

Google AJAX API Language e Prototype.js

/*
** @name	 : translate()
** @description  : translate
*/
function translate() {
$$('[rel="translate"]').each(
function(e) {
google.language.translate(e.innerHTML, 'it', 'en',
function(result) {
if (result.translation) {
e.innerHTML = result.translation;
} else {
alert( 'Translate Error!

' + result.error.message );
}
}
);
}
);
}

source

State Controller

document.observe('dom:loaded', function(){
// instance the class...it is available via 'controller'
controller = new StateController();
});

var StateController = Class.create({

initialize: function(){
util.trace('Control this.');

this.lastHash = '';
this.ready = true;

Event.observe(window, 'load', this.loaded.bind(this));
document.observe('receiver:stateChange', this.stateChange.bind(this));
//document.observe('receiver:hashChange', this.hashChange.bind(this));
},

loaded: function(){
util.trace('Got loaded');
//observe for hash changes
this.observeHash();
},

stateChange: function($event){
// when a state change is invoked, change the hash
util.trace('change hash '+ window.location.hash);
// add slash for aesthetics...looks like swfaddress
this.setHash($event.memo.destination);
},

observeHash: function(){
//when hash changes fire receiver:hashChanged
new PeriodicalExecuter(function(pe){
if (window.location.hash == this.lastHash) {
// hash hasn't changed, bail
return;
}
// hash has changed, take note and fire receiver:stateChange
this.lastHash = window.location.hash;
util.trace('New hash');
document.body.fire('receiver:hashChange', {destination: window.location.hash});

}.bind(this), .1);
},

fireEvent: function($destination){
//method for flash to send destination
document.body.fire('receiver:stateChange', {destination: $destination});
},

getHash: function(){
// returns the hash stripped of #/
return window.location.hash.sub('#/', '')
},

setHash: function($destination){
// formats hash to #/destination
window.location.hash = '/'+$destination;
},

getRelativeURL: function($url){
// pulls protocol, host and path from url to return location
var absolute = window.location.protocol+'//'+window.location.host+window.location.pathname;
util.trace(absolute+ '  ' + $url);
return $url.sub(absolute, '');
},

ready: function(){
return this.ready;
},

sitePageTitle: function(destination, delimiter){
var pathArray = destination.split('/').invoke('capitalize');
pathArray.unshift(document.title.split(' '+delimiter+' ').last());
pathArray.reverse();
return pathArray.join(' '+delimiter+' ');
}

});

source

jQuery AJAX navigation

$(document).ready(function() {

// Check for hash value in URL
var hash = window.location.hash.substr(1);
var href = $('#nav li a').each(function(){
var href = $(this).attr('href');
if(hash==href.substr(0,href.length-5)){
var toLoad = hash+'.html #content';
$('#content').load(toLoad)
}
});

$('#nav li a').click(function(){

var toLoad = $(this).attr('href')+' #content';
$('#content').hide('fast',loadContent);
$('#load').remove();
$('#wrapper').append('&lt;span id="load"&gt;LOADING...&lt;/span&gt;');
$('#load').fadeIn('normal');
window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
function loadContent() {
$('#content').load(toLoad,'',showNewContent())
}
function showNewContent() {
$('#content').show('normal',hideLoader());
}
function hideLoader() {
$('#load').fadeOut('normal');
}
return false;

});
});

source