SetInterval and ClearInterval -Javascript

I had been developing a real time chat system at my work  and the chat system takes some time to load(makes an ajax call to the backend that fetches users details,chat message,chat room id ,chat user role id etc..).and also there are multiple chat rooms based on user roles. The challenge was to wait for all of data to load  and then enable the chat system.

Solution :

The solution  is to wait for x interval of time and then make a call x time to check if the data we require is loaded.

 


var intialloading=false;
waitoperation();
var someinterval =setInterval(function(){

if(intialloading)

{

//clear the interval.

ClearInterval(someinterval);

}

},2000) // call function every 2 secs

function waitoperation()

{

//some call

intialloading=true;

}

 

 

 

 

Layouts in MVC

Layouts are used when there is a need to maintain a consistent look across multiple views.(Example : Header and footer across views).They are similar to master pages in ASP.NET.

Important Methods in Layouts :

@RenderBody():

1.Renders View and all of its components in layout page.

2.There can be only one RenderBody in a layout page.

Capture

@Renderpage():

1.Renders the specified page in layout.It takes an argument that specifies the location of page.


@RenderPage("~/Views/yourpage.cshtml");

2.There can be multiple RenderPage method in layout.

@Sections:

Renders the content of page in specified region  in layout.


@section("nameofsection,false")

1.Requires name of the section.If not specified exception will be thrown.

2.IsRequired attribute in section method has to be set to false,if section is not mandatory for every view,else an exception will be thrown.

rendersection