我试图每隔X秒使用setInterval调用一个setInterval()函数,我想在文档就绪函数中调用这个函数,并且我的aspx页面上的脚本管理器将EnablePageMethods设置为true。但这似乎不起作用,并返回PageMethod未定义的错误。下面给出了我的代码
<script type="text/javascript" >
$(document).ready(function () {
setInterval(function () {
PageMethods.LoadFile();
}, 1000);
});
</script> [WebMethod]
public void LoadFile()
{
Collection<string> stringcollection = new Collection<string>();
divLogSummary2.InnerHtml = "";
try
{
StringBuilder content = new StringBuilder();
if (string.IsNullOrEmpty(logFilePath))
{
return;
}
if (File.Exists(logFilePath))
{
using (FileStream fs = new FileStream(logFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (StreamReader sr = new StreamReader(fs))
{
while (!sr.EndOfStream)
{
stringcollection.Add(sr.ReadLine());
}
}
}
for (int i = stringcollection.Count - 30 ; i < stringcollection.Count; i++)
{
divLogSummary2.InnerHtml = divLogSummary2.InnerHtml + " <BR> " + stringcollection[i];
}
}
}
catch (Exception)
{
}
}我对Ajax比较陌生,任何帮助和洞察力都是非常感谢的。
谢谢,
发布于 2012-05-09 10:08:33
您的方法应该声明为静态的,以便与PageMethods一起使用。
[WebMethod]
public static void LoadFile()
{
.....
}诚挚的问候
https://stackoverflow.com/questions/10513912
复制相似问题