AJAX Page - Send complex server objects to client

See how to send data back to client.


C#

// for complex objects the return type should be ArrayList
public ArrayList callback()
{
	// simple ArrayList - contains simple data type objects
	ArrayList list1 = new ArrayList();
	list1.Add("value 1");
	list1.Add(100);

	// complex ArrayList - includes complex data type objects (another ArrayList)
	ArrayList list0 = new ArrayList();
	list0.Add(list1);
	list0.Add("other value");
	list0.Add(2);

	return list0;
} 



JavaScript (using synchronous callback):

var result = ob_post.post(null, "callback");
var elem1 = result[0][1]; // 100
var elem2 = result[1]; // 'other value'



JavaScript (using asynchronous callback):

ob_post.post(null, "callback", endcallback);
function endcallback(result)
{
	var elem1 = result[0][1]; // 100
	var elem2 = result[1]; // 'other value'
}