$.Ajax ( server_data_json )
AJAX implementation is often complex and browser specific. NedilJS AJAX apis are simpler and removes the complexities invloved.
$.Ajax takes server url and cache as inputs and returns the object reference of ajaxFactory.
Parameters
NameTypeDescription
server_data_jsonJSONShould provide server url and cache flag as input in JSON
FieldsDescription
urlServer URL which handles AJAX request
cacheflag to denote browser caching is enabled for AJAX request. Default is true. To force the browser to make a fresh request, turn off cache flag
Returns
TypeDescription
Object Reference of ajaxFactoryWill be used to make AJAX request. Explained later in this page.
		$.domLoaded(function() {

			var ajax = $.Ajax({
				url : "SERVER_URL",
				cache : false
			});
			
		});						
						
.send( request_data_json ) on ajaxFactory object
send() function will be used on ajaxFactory object. This function makes the actual AJAX request to the server and recieves the response. It takes data, type and handlers as JSON input parameter.
Parameters
NameTypeDescription
request_data_jsonJSONShould provide AJAX request information as input in JSON
FieldsDescription
typeGET / POST ( Default is GET )
datatypetext / xml / json / jsnop ( Default is text )
dataRequest query parameters/ data in JSON with name and value
asyncSynchronous or Asynchronous (Default is true)
successSuccess callback function when server responds successfully
failFailure callback function when request fails
callbackCallback function for JSONP request. If not provided, Success function will be used
		$.domLoaded(function() {

			var ajax = $.Ajax({
				url : "SERVER_URL",
				cache : false
			});
			
			ajax.send({
				type : "GET",
				datatype : "text",
				data : { "name" : "Senthil", "age" : 24},
				async : true,
				success : function(res) {
					console.log(res);
				},
				fail : function() {
					console.log("failure");
				}
			});
			
		});						
						


Example 1 - Text
This example sends name and age data to the server and server responds with text format.
JS
		$.domLoaded(function() {

			$.get("#ajax1").on("click", function() {
			
				$.Ajax({ url : "../../ajax/AjaxServer.php"}).send({
				
					data    : { name : "Senthil", age : 24 },
					
					success : function(res) {
						$.get("#result").html(res);
					},
					
					fail    : function() {
						$.get("#result").html("Some error has occured");
					}
					
				});
				
			});
			
		});						
						
Result
Example 2 - XML
This example sends name and age data to the server with xml datatype and server responds with xml format.
JS
		$.domLoaded(function() {

			$.get("#ajax1").on("click", function() {
			
				$.Ajax({ url : "../../ajax/AjaxServer.php"}).send({
				
					data     : { name : "Senthil", age : 24 },
					
					datatype : "xml",
					
					success  : function(res) {
						var root = res.documentElement;
						var name = root.getElementsByTagName("name")[0];
						var age = root.getElementsByTagName("age")[0];
						$.get("#result").html("Name : " + name.innerHTML + "
Age : " + age.innerHTML); }, fail : function() { $.get("#result").html("Some error has occured"); } }); }); });
Result
Example 3 - JSON
This example sends name and age data to the server with JSON datatype and server responds with JSON format.
JS
		$.domLoaded(function() {

			$.get("#ajax1").on("click", function() {
			
				$.Ajax({ url : "../../ajax/AjaxServer.php"}).send({
				
					data     : { name : "Senthil", age : 24 },
					
					datatype : "json",
					
					success  : function(res) {
						$.get("#result").html("Name : " + res.name + "
Age : " + res.age); }, fail : function() { $.get("#result").html("Some error has occured"); } }); }); });
Result