Im calling server code (c#) by jQuery ajax method or ajax pagemethods. While calling, server code executes two times and returns failed callback method.
This code is not working in recently hosted new server. In existing servers, this code working without any problem and returning success callback method.
JS Code:
var myVal = 'Test val';
var input = {
'val1': myVal
};
$.ajax({
async: true,
type: 'POST',
url: 'MyPage.aspx/MyFunction',
data: JSON.stringify(input),
dataType: 'json',
contentType: 'Application/json',
success: QCErrorResult,
error: QCErrorFailedMethod
});
OR
JS Code:
PageMethods.MyFunction(myVal, QCErrorResult, QCErrorFailedMethod);
C# Code:
[WebMethod(EnableSession = false)]
public static string MyFunction(string val1)
{
// My code here
}
Same issue while calling my api by jquery ajax.
In App_Start/RouteConfig comment the line settings.AutoRedirectMode =RedirectMode.Permanent if its there. For multiple times calling, check the post backs of the page.