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)
$.post("yourpage.aspx",
{
d1: "v1"
},
function(data) {
//now the data will hold the name of the function
window[data]();
}
);
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.