I'm using VisualStudio 2008 and have a method on an ASPX page I am trying to call with javascript using jQuery as shown below. I am just getting the page's HTML back. The webmethod is not called. Interestingly, if I change the name of the webMethod to call in the javascript, I still get back the HTML. Not an error saying the webMethod cannot be found.
I've tried changing the data argument to "{ 'dummy':0 }", but that doesn't help.
I've used this strategy without problem in a new VS 2010 app, but can't seem to get it to work on an existing app in VS 2008 that I am adding a page to. (trying to add a twist to an old app) I've looked at what firebug is telling me in firefox, and all looks right.
Any help is greatly appreciated.
C# WebMethod decalaration:
[WebMethod()]
public static string getQuestionnaires(int dummy)
{
System.Diagnostics.Debug.WriteLine("getQuestionnaires called");
SqlCommand command = new SqlCommand();
command.CommandText = "dbo.ws_GetPSQuestionnaire";
command.CommandType = CommandType.StoredProcedure;
DataTable dtQuestionnairesRaw = Utilities.ReturnDataSet(command).Tables[0];
DataTable dtQuestionnaires = new DataTable();
dtQuestionnaires.Columns.Add(new DataColumn("questionnaireID", typeof(int)));
dtQuestionnaires.Columns.Add(new DataColumn("name"));
foreach (DataRow dr in dtQuestionnairesRaw.Rows)
{
DataRow drNew = dtQuestionnaires.NewRow();
drNew["questionnaireID"] = dr["questionnaireID"];
drNew["name"] = Utilities.RemoveHTMLTags(dr["name"].ToString());
dtQuestionnaires.Rows.Add(drNew);
}
dtQuestionnaires.AcceptChanges();
return (JsonConvert.SerializeObject(dtQuestionnaires, Formatting.Indented));
}
I am calling it with this javascript. My error function is ALWAYS called.
$(document).ready(function() {
var request = $.ajax({
type: "POST",
url: "/crs4/admin/editPSQuestionnaire.aspx/getQuestionnaires",
contentType: "application/json; charset=utf-8",
data: "{ 'dummy':'0' }",
dataType: "json",
success: populateQuestionnaires,
error: AjaxFailed
});
});