Calling server side method from asp.net page
I'm trying to use jQuery to call a server side method in ASP.Net 2.0, but I keep getting my error message that I set in the error function.
Can someone show me where I can fix my code to get the server side method to be called and get the success message?
-----------------HTML image that calls popup-----------------
- <img id="imgDisciplineComments" src="assets/images/edit_icon.gif" class="editIcon handCursor" style="display: none;" alt="Add program/discipline outcome comments" />
-----------------HTML Hidden Div snippett-----------------
- <div id="divDisciplineComments" title="Program Discipline Comments" style="text-align: left; display: none;">
- <input type="text" id="hiddenDisciplineComments" class="hiddenDisciplineComments" runat="server" />
- </div>
-----------------jQuery Dialog-----------------
- $(function () {
- $("#divDisciplineComments").dialog({
- autoOpen: false,
- show: "blind",
- width: 500,
- height: 480,
- draggable: false,
- position: 'center',
- modal: true,
- buttons:
- {
- "Add": function () {
- var name = $("#<%= hiddenDisciplineComments.ClientID %>").val();
- $.ajax({
- type: 'POST',
- url: 'DisciplineRecordReview.aspx/SaveComments', //This is the correct name of my page and method call and case is correct.
- data: "{'name':'Hello World'}",
- contentType: "application/json; charset=utf-8",
- dataType: "json",
- success: function (msg) {
- if (msg.d) {
- alert("Successfully added new item");
- }
- },
- error: function () {
- alert("Error! Try again...");
- }
- });
- },
- "Cancel": function () {
- $(this).dialog("close");
- }
- }
- });
- $("#imgDisciplineComments").click(function (event) {
- event.preventDefault();
- $("#divDisciplineComments").dialog("open");
- });
- });
-
-----------------Server side method snippett-----------------
[WebMethod]
public static bool SaveComments(String name)
{
return true;
}