I am having an issue with my Ajax code polling my IIS/ASP server. After calling msgPoll("") once, the function seems to be invoked repeatedly instead of every 30 seconds. Can you help me identify what mistake I might be making?
var msgTimOut;
function msgPoll(text) {
var msgData = {};
msgData.UID = $("#hidUID").val();
msgData.data = text;
$.ajax({
type: "POST",
url: "WSWebJudge.asmx/MsgPoll",
cache: false,
data: JSON.stringify(msgData),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
resp=JSON.parse(data.d);
if (resp.status == 1) setMsg(resp.msg);
if (msgTimOut) clearTimeout(msgTimOut);
msgTimOut = setTimeout(msgPoll(""), 3000);
},
error: function (jqXHR, textStatus, errorThrown) {
alert("Messaging - textStatus: " + textStatus + " errorThrown: " + errorThrown);
}
});
}