Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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:

$.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:

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.

share|improve this question
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.