title: Using setInterval with PageMethods
body: <p>I am trying to call a LoadFile() function every X seconds using setInterval, and I want to call this in my document ready function , and a scriptmanager on my aspx page sets EnablePageMethods as true.
  But this doesnt seem to work and returns PageMethod not defined error.
  My code is given below </p>
  
  <hr>
  
  <p></p>
  
  
  
  <pre><code>&lt;script type="text/javascript" &gt;
      $(document).ready(function () {
          setInterval(function () {
              PageMethods.LoadFile();              
          }, 1000); 
      });
  &lt;/script&gt;
  </code></pre>
  
  <hr>
  
  <pre><code>    [WebMethod]
      public void LoadFile()
      {
          Collection&lt;string&gt; stringcollection = new Collection&lt;string&gt;();
          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 &lt; stringcollection.Count; i++)
                  {
                      divLogSummary2.InnerHtml = divLogSummary2.InnerHtml + " &lt;BR&gt; " +                       stringcollection[i];
                  }
  
              }
          }
          catch (Exception)
          {
  
          }
      }
  </code></pre>
  
  <p>I am relatively new to Ajax, any help and insight is much appreciated.</p>
  
  <p>Thanks,</p>