vinod's erudition

we learn everything from failure not from success so keep failing

Home Ruby Rails Javascript Python Agentic AI

Jquery ui Dialog box displays the content by ajax its dead hot ghost rider

Posted on March 05, 2014 by vinod

At many times i was eager to learn ajax,yeah obviously the beauty of it is it brings the data in a fraction of seconds without loading the page.at that time i was searching for some good blogs over there and i came across a good blog where the author has explained how to pop up modal overlay dialog box and retrieve the contents asynchronously.it was mind blowing i cant believe it because this much less code does big things that is jquery.

####Options Default value Usage

and i am damn sure you wont be able to get these compicated things so lets begin to practical work before that i will explain small snippet of code to make it clear

	$("#div1").dialog({
					autoOpen:false,
					modal:true,   //open as modal overlay

					width: 600, //width size

					height:300, //height size

					buttons:{    //buttons in dialog box can be added

						"Dismiss": function(){     //adding dismiss button

							$(this).dialog("close");
						}
					}
					
})

Explanation: we are defining the modal dialog box to the div element and initializing with values such as it should be modal overlay,width and hieght of it and inserting some buttons and necessary actions in anonymous functions in dialog box .

$("button#hitme").on('click',function(e){
				console.log("clicked");
				e.preventDefault();
				$("#div1").html("");
				$("#div1").dialog("option","title","Loading...").dialog("open");
				$("#div1").load("what_i_am.txt",function(){
					$("#div1").dialog("option","title",$(this).find("h2").text());
					$(this).find("h2").remove();
				});

###Explanation: