April 21, 2011

call jquery function from server

Question by user321963

In asp.net, How can i trigger client side jquery event from server. I want to implement it in my chat section… current the chat seems to work fine… but it has one problem… i have to send a request every 5 seconds from client’s browser to the his chat history.. which i feel is not a good idea…

can anyone provide any solution for my problem

Answer by Starx

Although, I am not that skilled in ASP.Net, this problem can be solved in another way.

Have the server return the name of function you need to execute, then call it in the callback function?

Kinda like this (It is just a typo but)

      d1: "v1"
   function(data) {
     //now the data will hold the name of the function

Now you can wrap the above code, in the another function, and set up a timer, to check for the response regularly, and execute the function if a condition is matched.

P.S. I have skipped the part, where the scripts check if the condition is matched.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+


Please fill the form - I will response as fast as I can!