vinod's erudition

we learn everything from failure not from success so keep failing

Home Ruby Rails Javascript Python Agentic AI

TODAY IM INTERESTED IN AJAX lets clear it

Posted on March 05, 2014 by vinod

####AJAX Introduction:

####Syntax: #####$(selector).load(URL,data,callback);

####callback function has three different parameter:

As a Simplestart i have tried to load text content from text file and display it webpage using load function.

<!DOCTYPE html>
<html>
	<head>
		<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
		<meta content="utf-8" http-equiv="encoding">

	</head>
	<body>
		<div id="div1"><h3>Hey guys this is the start of ajax</h3>
		</div>
		<button>Hit me and know what i am </button>
	
		<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
		<script>
		(function(){
			console.log("i m inside");
			$("button").on('click',function(){
				
				$("#div1").load("what_i_am.txt",function(resp,status,xhr){
					console.log("resp"+resp+"status:"+status+"xhr object"+xhr);
				});
			});
		})();
		</script>
	</body>
</html>

####Textfile to be rendered what_i_am.txt

I am a heavy hitting rubiest

Will emerge one day

####OUTPUT: index.html

resp<h2>I am a heavy hitting rubiest</h2>

Will emerge one day

status:success xhr object[object Object]