Abstract - Coding Web Applications
Home
Page 2 of abstract Page 3 of abstract Page 4 of abstract
Next slide

Resoa service invocation with AJAX based on JQUERY / JSON

// Defining namespaces
if (!org) org = {}; if (!org.resoa) org.resoa = {};
// Helper function for AJAX calls
org.resoa.getAJAXOptions = function (successHandler, errorHandler) {
	var options = {
		contentType : "application/json; charset=utf-8",
		dataType : "json", //service invocation is based on JSON
		url : "/service", //the URL of the resoa service domain 
		cache : false,
		type : "POST",
		complete : successHandler, //the success function
		error : errorHandler //the error function
	};
	return options;
};
 //we instance request object, using the auto-generated Javascript library	 
 var usr = new org.foo.user.User(); 
 //setting request values	 
 usr.setName("Jon_Smith");
 //set data to JSON representation of request object, call the Java service method 'exists'
 ajaxOptions.data = usr.toJson("exists"); 
//we call in synchronized way
 ajaxOptions.async = false;
 //performing the AJAX request
 var xmlReq = $.ajax(ajaxOptions);
 //examining the result, which is the JSON representation of the Java response object
 if (org.foo.user.Message.prototype.instanceOf(xmlReq.responseText)){
	 //creating Javascript Message object out of response JSON 
 	var msg = new org.foo.user.Message(xmlReq.responseText);
	//continue with business logic by examining the response...	
}

Characteristics of Resoa Rest