使用jQuery直接调用ASP.NET AJAX页面方法 - 500(内部服务器错误) [英] Using jQuery to directly call ASP.NET AJAX page methods -- 500 (Internal Server Error)

查看:828
本文介绍了使用jQuery直接调用ASP.NET AJAX页面方法 - 500(内部服务器错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习通过AJAX和ASP方法...

I'm learning about asp methods via ajax and...

于是,我做了FF。从该网站: http://encosia.com/使用-的jQuery到直接叩ASPNET-AJAX页面的方法/

So I tried doing the ff. from this site: http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/

在JS文件:

 $(document).ready(function () {
// Add the page method call as an onclick handler for the div.
$("#Result").click(function () {
    $.ajax({
        type: "POST",
        url: "WebForm1.aspx/GetDate",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            // Replace the div's content with the page method's return.
            $("#Result").text(msg.d);
        }
    });
});

});

在ASPX:

 <html>
<head>
<title>Calling a page method with jQuery</title>
<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
<script type="text/javascript" src="Scripts/JScript1.js"></script>
 </head>
  <body>
<div id="Result">Click here for the time.</div>
 </body>
 </html>

在code-背后:

namespace WebApplication1
 {
   public partial class WebForm1 : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    [WebMethod]
    [ScriptMethod(UseHttpGet = true)]
    public static string GetDate()
    {
        return DateTime.Now.ToString();
    }

}

}

当我在我的本地PC上VS工作室运行它,它工作得很好;然而,一旦文件被IIS服务器的部署,当我点击容器上给出了这样的错误:

When I run it on VS studio on my local PC, it works just fine; however, once the files are deployed in IIS server, it gives this error when I click on the container:

POST HTTP:///WebForm1.aspx/GetDate 500(内部服务器错误)

POST http:///WebForm1.aspx/GetDate 500 (Internal Server Error)

有什么在IIS中配置?或者是code有关的错误?

Is there something to configure in IIS? or is it code-related error?

推荐答案

尝试删除此行 [ScriptMethod(UseHttpGet = TRUE)] Becouse这条线是用来当你试图GET请求,当你看到这个例子中,他们正试图做一个POST请求,则不需要此行。

Try remove this line [ScriptMethod(UseHttpGet = true)] Becouse this line is used When you are trying a Get Request, When you see the Example, they are trying to do a POST request and this lines Is not needed.

[WebMethod]
    public static string GetDate()
    {
        return DateTime.Now.ToString();
    }

这篇关于使用jQuery直接调用ASP.NET AJAX页面方法 - 500(内部服务器错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆