据我所知,问题是PageMethod没有返回JSON。我是否需要在服务器端执行其他操作以正确格式化返回值?还有其他我想念的东西吗?

(注意:我现在正在针对IE8进行测试)

在客户端(使用jQuery 1.8.0):

$.ajax({
            type: "POST",
            url: "Test.aspx/GetDate",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: SuccessFunction,
            error: ErrorFunction
        });


在服务器端:

<WebMethod()> _
Public Shared Function GetDate() As String
    Return Date.Now.ToString
End Function

最佳答案

好的,所以我根据this较旧的问题弄清楚了。原来,我需要在web.config文件的system.web部分中执行以下操作:

<httpModules>
  <add name="ScriptModule"
     type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>


我想如果您使用Visual Studio创建“ AJAX网页”,则会自动为您设置,但是我试图将某些内容添加到较旧的ASP.NET页中。

07-25 22:02
查看更多