Take the 2-minute tour ×

I am trying to use jQuery ajax to call a WebMethod on an aspx page that I have in my application. I am following this article: http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/

I noticed that when I try to make the ajax call, it is giving me the page itself (myPage.aspx) and not the results of my WebMethod. At this point, I am basically using the code straight from the article above. The javascript is:

$(document).ready(function () {
        type: "POST",
        url: "myPage.aspx/GetDate",
        data: "{}",
        dataType: "json",
        success: function (msg) {
            // Replace the div's content with the page method's return.

The myPage.aspx code-behind for the WebMethod is:

    public static string GetDate()
        return DateTime.Now.ToString();

The strange thing is that I had it working on a separate test page, but when I tried to integrate it into the actual page where I want to use it, it doesn't. I couldn't find anything that resolved my issue when searching the site and web.

I'm running Sitecore 6.5 and .NET Framework version 4.0. Can anyone help or provide insight?

share|improve this question
Why dont you include error function like this error: function (xhr, status, error) { var msg = JSON.parse(xhr.responseText); alert(msg.Message);} and see if it is throwing any errors or else use firebug to check the request and resposne –  user1042031 Jul 2 '12 at 17:08
@user1042031 I previously looked at the Response headers and it was returning text/html which was the HTML of the page itself. I am not really sure why this is happening though. –  user1496624 Jul 2 '12 at 18:01

3 Answers 3

I am only familiar with PHP but usually you have to json_encode() your array before returning back. So for example in php

$TestArray['d'] = "All My HTML";
echo json_encode($TestArray);

//Then in Jquery


and make sure there is a div with the id of Result...

share|improve this answer

Typically, that happens when the request is either not a POST or doesn't have the application/json Content-Type set.

I'm not familiar with Sitecore, but others seem to have had trouble with it interfering with page methods: How to use jquery ajax and webmethod with sitecore

share|improve this answer

I think the problem is that Sitecore's URL rewriter will handle the request and ignore the /GetDate part of your url.

Therefore you must add your aspx to the <setting name="IgnoreUrlPrefixes" /> setting.

share|improve this answer
I put in a support ticket with Sitecore and they responded that this is caused with an issue in the RewriteModule. They did say that it is not reproducible in 6.5-Update 4, so upgrading Sitecore may do the trick, but I am unable to do so right now. I did try adding my page to the IgnoreUrlPrefixes setting, but that did not help. Thanks for the response! –  user1496624 Jul 9 '12 at 17:17
This is not a option because you'll lose the Sitecore context –  ydd1987 Sep 24 '12 at 17:12

Your Answer


