3
Answers

Working with web Method and ajax

Hi 
 
 I have the following on my Calender.aspx code behind:
 
[WebMethod]
public static void saveTask(string DATE, int IDEVENT)
{
using (ProjectManagementEntities db = new ProjectManagementEntities())
{
var updateTask = db.tb_Task.FirstOrDefault(x => x.Id == IDEVENT);
updateTask.StartDate = Convert.ToDateTime(DATE);
db.SaveChanges();
}
}
 
and the following script:
 
function saveTask(theDATE, theIDEVENT) {
$.ajax({
type: "POST",
url: "Calender.aspx/saveTask",
data: JSON.stringify({ date : theDATE, id : theIDEVENT }),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
alert('Task Updated Successfully.');
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("Error");
}
});
};
 
The problem is I can't debug the webMethod saveTask, i put a breakpoint but t doesn't even hit the page. It seem the script does not hit the webMethod so can you please assist.
 
Thanks.
 
 
Answers (3)