I’m new to jQuery. I need to call the method after some interval.
$(document).ready(function pageLoad() {
setTimeout('SetTime2()', 10000);
});
(function SetTime2() {
$.ajax({
type: "POST",
url: "MyPage.aspx/myStaticMethod",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
// Replace the div's content with the page method's return.
//$("#Result").text(msg.d);
}
});
});
It says, Uncaught ReferenceError: SetTime2 is not defined.
What is the correct syntax? Thanks.
Change to this:
You need to just define a normal function with your declaration of
SetTime2(). No parens around it.Also, you don’t want to pass a string to
setTimeout(), you want to pass an actual function reference without the quotes or the parens.Note: you could also do this using an anonymous function: