I want to send data using ajax from jquery to c# (note: im sending request to the same page).
I am following this tutorial http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/.
**NOTE: This is a asp.net 3.5 on SharePoint 2010 webpart solution.**
This is my jquery code:
and in c#, the main file is "PDFLibraryUserControl.ascx.cs". This is the one that has the "Page_Load" function.
However I have another class file called "SaveStructure.cs":
I expect to get an alert saying "1234", but instead I get this:
![]()
Does it have something to do with the function `saveOrder` being on another file than the main one? Or maybe my url is not correct? I don't want to hardcode the url in it, because the current page is the aspx page and also contains the jquery code to send the POST (to the same page).
Does anyone know whats wrong and can fix this?
Thanks.
I am following this tutorial http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/.
**NOTE: This is a asp.net 3.5 on SharePoint 2010 webpart solution.**
This is my jquery code:
$.ajax({ type: "POST", url: getURLWithoutQuery() + "/saveOrder", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { alert(msg.d); } }); // return the url of the current page without any query parameters function getURLWithoutQuery() { return location.protocol + '//' + location.host + location.pathname; }
and in c#, the main file is "PDFLibraryUserControl.ascx.cs". This is the one that has the "Page_Load" function.
However I have another class file called "SaveStructure.cs":
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web.UI; using System.Web.Services; namespace PDFLibrary.PDFLibrary { public partial class SaveStructure : Page { [WebMethod] public static int saveOrder() { return 1234; } } }
I expect to get an alert saying "1234", but instead I get this:

Does it have something to do with the function `saveOrder` being on another file than the main one? Or maybe my url is not correct? I don't want to hardcode the url in it, because the current page is the aspx page and also contains the jquery code to send the POST (to the same page).
Does anyone know whats wrong and can fix this?
Thanks.