Click here to Skip to main content
15,885,309 members
Articles / Programming Languages / Java

Ajaxion - Standalone AJAX - Part 2 of 2 - C# and Java Example

Rate me:
Please Sign up or sign in to vote.
4.97/5 (34 votes)
22 Jan 2013CPOL5 min read 55.2K   1.4K   42  
An article about how to keep AJAX simple as it is and get the most out of it.
// Page initialisation

var ajaxion = new Ajaxion("../ajaxionTest");
var getTextEvent = "getText";

function onLoad()
{
	//var handler = "ajaxion.get('getText', getTextCallback)";
	//window.document.getElementById("btn").setAttribute("onclick", handler);
}

// Page specific events handlers and parameters

function parseEventParam(eventId)
{
	beginEvent(eventId);
	var eventParams;
	switch (eventId)
	{
		case getTextEvent :
			window.document.getElementById("txDiv").innerHTML = "Retrieve Area";
			eventParams = getText(eventId);
			break;

         default:
            eventParams = null;
				alert("Unexpected ajaxion event id: " + eventId);
			break;
	}
	return eventParams;
}

// Override ajaxion.endEvent and ajaxion.endEvent for this page
ajaxion.beginEvent = beginEvent;
ajaxion.endEvent = endEvent;

function beginEvent(eventId)
{
	ajaxion.showStatus("status", "Processing...", "coral");
	ajaxion.showStatusImg("statusImg", "images/processing.gif");
	ajaxion.setEventMonior(eventId, null);
}
function endEvent()
{
	ajaxion.setEventMonior(null, null);
	ajaxion.showStatus("status", "Ready", "silver");
	ajaxion.showStatusImg("statusImg", "images/ready.jpg");
}

// getTextEvent

function getText(param)
{
	return param;
}
function getTextCallback()
{
	try
	{
		if (ajaxion.isEventConsumed())
		{
			window.document.getElementById("txDiv").innerHTML = ajaxion.getResponseString();
			ajaxion.endEvent();
		}
	}
	catch (ex)
	{
		ajaxion.endEvent();
		alert("getTextCallback exception: " + ex.description);
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
New Zealand New Zealand
Coder

Comments and Discussions