I have an .Ajax method that calls a method on the page behind (does some logic, then calls a WCF service, then returns an object) that looks like this:
$.ajax({
type: 'POST',
url: 'MyPage.aspx/TestMethod',
dataType: "json",
contentType: "application/json",
data: "{'Id': '" + Id + "'}",
success: function (data) {
$("#randomElement").html(data.d.Foo);
},
error: function ((xhr, textStatus, error){
alert(xhr.statusText);
alert(textStatus);
alert(error);
});
And the page behind:
[System.Web.Services.WebMethod]
public static MyObject TestMethod(string Id)
{
//Logic removed for readability!
return MyService.GetStuff(Id);
}
This works perfectly fine on my local machine, but fails to work when I deploy to my server.
I have determined that the page behind method does not get called (i.e. the error is in calling TestMethod(), not TestMethod() calling the service).
I have also placed an alert before the .ajax method to show me the path of the page I am on just in case it was doing something funny with the uri on the live server, and it comes back as "/MyPage.aspx" as I would expect.
I also changed the "url:" to the full uri to see if that helped and it didn't.
After running fiddler with custom errors off, I get the following error:
{"Message":"Thread was being aborted.","StackTrace":" at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)\r\n at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)\r\n at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)\r\n at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)\r\n at System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target, IDictionary
2 parameters)\r\n at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary
2 parameters)\r\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.Threading.ThreadAbortException"}
MyPage.asmx/TestMethod
instead ofMyPage.aspx/TestMethod
? – John Pick