Hi,
I have two application pages, one should call the other using AJAX to obtain some data.
I'm using this code in the first page:
<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server"><script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script></asp:Content><asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server"><script> function MyClass() { this.url = ''; this.start = function () { this.url = '<%= SPContext.Current.Web.Url %>/_layouts/MyProject/Result.aspx'; this.execute('some_value'); }; this.execute = function (k) { // FIRST CALL $.ajax( { type: "GET", url: this.url, data: "param1=" + k, async: true, cache: false, success: function (data) { alert(data); }, error: function (data) { alert('Error'); } }); /* // SECOND CALL $.ajax( { type: "POST", url: this.url, data: '{ "param1": "' + k + '" }', async: true, cache: false, success: function (data) { alert(data); }, error: function (data) { alert('Error'); } }); */ /* // THIRD CALL $.ajax( { 'type': 'POST', 'url': this.url + '/GetSomething', 'data': '{ "param1": "' + k + '" }', 'contentType': 'application/json; charset=utf-8', 'dataType': 'json', 'success': function (data) { alert(data); }, 'error' : function (xhttp, textStatus, errorThrown) { alert('Error'); } }); */ }; } var _my; $(document).ready(function () { _my = new MyClass(); _my.start(); });</script></asp:Content>
The content of the second page can be anything.
If I make the AJAX call using GET (see First Call), this code works.
The problem is when I try to use POST (see Second Call), the success callback is called, but the content of the page is the standard sharepoint error page containing a Correlation ID. In the ULS I've found this error:
Non-OAuth request. IsAuthenticated=True, UserIdentityName=0#.w|machine-name\administrator, ClaimsCount=22
Application error when access /_layouts/MyProject/Result.aspx, Error=File '/_layouts/MyProject/Result.aspx' doesn't exist. in System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath) in System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) in System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) in System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound) in System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp) in System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) in System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() in System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
I've also tried using a Page Method (a public static method with [WebMethod] in that page, in my example called GetSomething, see Third call) but in this case the Error callback is called, and the content is the same standard error page, with the same error in the ULS.
This exact code works in SharePoint 2010.
What has changed in 2013 that blocks AJAX request using POST?