ReferenceError: getMessage not defined

ideoneshisy

New Member
I am building a messaging area similar to facebook and I am using ajax with jquery and a asmx web service to serve the html to the client. My li click event works when the content is first loaded on page load using c#, but when ajax runs and refreshes the content from the web service the li event doesn't work anymore. This an example of the html that is returned from the web service\[code\]<ol class="messagesrow" id="messages"><li id="2345"><div>Test Element</div></li></ol>\[/code\]Web service markup\[code\][WebMethod]public string GetMessagesByObject(string id, string objectid, string userid, string timezone){ string output = string.Empty; try { StringBuilder str = new StringBuilder(); DataSet results = results from store procedure str.Append("<ol class=\"messagesrow\" id=\"messages\">"); for (int i = 0; i < results.Tables[0].Rows.Count; i++) { DataRow row = results.Tables[0].Rows; DateTime date = Convert.ToDateTime(row["CreateDate"].ToString()).AddHours(Convert.ToDouble(timezone)); if (!TDG.Common.CheckStringForEmpty(row["ParentMessageID"].ToString())) { str.Append("<li id=\"" + row["ParentMessageID"].ToString() + "\">"); } else { str.Append("<li id=\"" + row["MessageID"].ToString() + "\">"); } str.Append("<div style=\"width:100%; cursor:pointer;\">"); str.Append("<div style=\"float:left; width:25%;\">"); if (!TDG.Common.CheckStringForEmpty(row["ImageID"].ToString())) { str.Append("<img src=http://stackoverflow.com/"/Resources/getThumbnailImage.ashx?w=48&h=48&id=" + row["ImageID"].ToString() + "\" alt=\"View Profile\" />"); } else { str.Append("<img src=http://stackoverflow.com/"/images/noProfileImage.gif\" alt=\"View Profile\" />"); } str.Append("</div>"); str.Append("<div style=\"float:left; width:75%; padding-top:4px;\">"); str.Append("<strong>" + row["WholeName"].ToString() + "</strong>"); str.Append("<br />"); if (row["BodyMessage"].ToString().Length < 35) { str.Append("<span class=\"smallText\">" + row["BodyMessage"].ToString() + "</span>"); } else { str.Append("<span class=\"smallText\">" + row["BodyMessage"].ToString().Substring(0, 35) + "</span>"); } str.Append("<br /><span class=\"smallGreyText\">" + String.Format("{0:g}", date) + "</span>"); str.Append("</div>"); str.Append("</div>"); str.Append("</li>"); } str.Append("</ol>"); output = str.ToString(); } catch (Exception ex) { throw ex; } return output;}\[/code\]Jquery markup\[code\]$(document).ready(function () { $("ol#messages li").click(function () { var id = $(this).attr("id"); getMessage(id); });});function getMessage(id) { var timezone = $('#<%= hdfTimezone.ClientID %>').val() var userid = $('#<%= hdfUserID.ClientID %>').val() $.ajax({ type: "POST", async: false, dataType: "json", contentType: "application/json; charset=utf-8", url: "/Resources/MessageWebService.asmx/GetMessage", data: "{'id':'" + id + "','timezone':'" + timezone + "','userid':'" + userid + "' }", success: function (data) { $('#<%= hdfMessageID.ClientID %>').val(id); $('#<%= ltlMessages.ClientID %>').html(data.d); }, error: function (data) { showError(data.responseText); } }); }\[/code\]
 
Back
Top