title: Getting data with ajax through HttpHandler
body: <p>So I'm working on getting some data with AJAX. All appears to work okay, but I'm not actually getting the data on my page:</p>
  
  <pre><code>&lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      function getMailDetail(mailId) {
          $.ajax({
              type: "GET",
              url: "GetMail.ashx",
              data: "mid=" + mailId,
              success: function (data) {
                  console.log(data);
                  var pnlMail = $('#&lt;%= pnlMail.ClientID %&gt;');
                  var lblFrom = $('#&lt;%= lblFrom.ClientID %&gt;');
                  var lblDate = $('#&lt;%= lblDate.ClientID %&gt;');
                  var lblSubject = $('#&lt;%= lblSubject.ClientID %&gt;');
                  var lblMessage = $('#&lt;%= lblMessage.ClientID %&gt;');
  
                  lblFrom.text(data.From);
                  lblDate.text(data.Date);
                  lblSubject.text(data.Subject);
                  lblMessage.text(data.Message);
  
                  pnlMail.css("display", "block");
              }
          });
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>I've logged <code>data</code> to check it's value. As this is my first try at this, I'm not exactly sure what to expect, however, I believe I should be getting back name:value pairs. Currently the console is logging absolutely nothing. No value at all.</p>
  
  <p>Here's my HttpHandler:</p>
  
  <pre><code>    public void ProcessRequest(HttpContext context)
      {
          string mailid = context.Request.QueryString["mid"].ToString();
          context.Response.ContentType = "text/json";
  
          context.Response.Write(showMailDetail(mailid));
      }
  
      protected string showMailDetail(string id)
      {
          int mailid = int.Parse(id);
  
          string From = "";
          DateTime Date = DateTime.Now;
          string Subject = "";
          string Message = "";
  
          MySqlContext db = new MySqlContext();
  
          string sql = "select m.datesent, m.subject, m.message, u.firstname, u.lastname from mail m inner join users u on m.sender = u.userid where m.mailid = @id";
  
          List&lt;MySqlParameter&gt; args = new List&lt;MySqlParameter&gt;();
          args.Add(new MySqlParameter() { ParameterName = "@id", MySqlDbType = MySqlDbType.Int32, Value = mailid });
  
          MySqlDataReader dr = db.getReader(sql, args);
  
          if (dr.HasRows)
          {
              dr.Read();
  
              From = (string)dr["firstname"] + " " + (string)dr["lastname"];
              Date = dr.GetDateTime("datesent");
              Subject = (string)dr["subject"];
              Message = (string)dr["message"];
          }
          dr.Close();
  
          string result = "{ 'From' : " + From + ", 'Date' : " + Date.ToString("yyyy/MM/dd HH:mm:ss") + ", 'Subject' : " + Subject + ", 'Message' : " + Message + " }";
  
          return result; 
      }
  </code></pre>
  
  <p>Can anyone help me figure out why I'm not getting anything here? I'm completely prepared for the possibility that I'm doing this wrong...</p>
  
  <p>I wrote the code based on the article at
  <a href="http://www.codeproject.com/Articles/170882/jQuery-AJAX-and-HttpHandlers-in-ASP-NET" rel="nofollow">http://www.codeproject.com/Articles/170882/jQuery-AJAX-and-HttpHandlers-in-ASP-NET</a></p>
  
  <p><strong>EDIT</strong><br>
  Found that I was using an incorrect column name in my sql - should have been <code>m.sender</code> not <code>m.senderid</code> ... However, I now have another problem.</p>
  
  <p>When I trigger the Handler, I get the following in Chrome's console:</p>
  
  <blockquote>
    <p>GET GetMail.ashx?mid=1 500 (Internal Server Error) jquery.min.js:2</p>
  </blockquote>
  
  <p><strong>EDIT 2</strong><br>
  Corrected more mistakes in the code on the Handler and now there are no errors appearing anywhere, but it doesn't look like the click is actually triggering anything at all...</p>
  
  <p>Not sure how to proceed here...</p>