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:

    type: "POST",
    url: getURLWithoutQuery() + "/saveOrder",
    data: "{}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (msg) {

// 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
        public static int saveOrder()
            return 1234;

I expect to get an alert saying 1234, but instead I get this:

enter image description here

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.

  • 1
    Can you look in the ULS and find the actual error associated with that correlation ID? – RJ Cuthbertson Jun 27 '13 at 3:08
  • The url option can be relative, so all you need is window.location.pathname. – Chloraphil Jun 27 '13 at 14:28
  • ULS logs, or if this is not production turn off customerrors so you get a stacktrace instead, much easier than looking in the logs – BinaryJam Jul 8 '13 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.