Sbonga Mathobela

Sbonga Mathobela

  • NA
  • 68
  • 7.6k

Working with web Method and ajax

Jun 6 2017 5:53 AM
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)