views:

8

answers:

1

Well i started by creating a new asp.net webapplication in VS2010 It created a solution that included jquery 1.4.1

After that i created an file named ajax.aspx and added the following in the code behind file:

<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Shared Function GetDate() As String
    Return Date.Now.ToString()
End Function

Then i added the following to "HeaderContent" in the "Default.aspx" file

<script language="javascript" type="text/javascript">
    $(document).ready(function () {
        $.ajax({
            type: "POST",
            url: "Ajax.aspx/GetDate",
            data: "{}",
            contextType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                var result = msg.d;
                alert(result);
            },
            error: function (msg) {
                alert("Failed!");
            }
        });
    });
</script>

and i added the Jquery js reference in the master page..

but when i run the project i get "Failed" and the response text is the content of my ajax.aspx... why does this give me the content and not the result of the function?

Note: the GetDate function is never run (i placed a break point there)

A: 

Most probably ScriptModule is missing from the pipeline although I believe it should be there by default in .NET 4.0. May be you can add it to you config file to see if problem gets solved:

<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

You need to look one for the .NET version 4.0.

Another issue can be URL routing - check this thread: http://forums.asp.net/p/1599846/4066920.aspx

VinayC
tryed adding it no effect :(, also as far as i know there is no url rewriting on the web page...
Petoj