简体   繁体   English

AJax内部服务器错误500

[英]AJax Internal Server Error 500

I have a page method issue I have this page method on a ASP.net webform 我有一个页面方法问题,我在ASP.net Webform上有这个页面方法

   [WebMethod(true)]
    public static int GetInt(int id){
          return 10;
   }

and I call it from JQuery like this 我从JQuery这样叫它

   $.ajax({
            type: "POST",
            url: "webforms.aspx/GetInt",
            data: "{id:'1'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
            },
            error: function (err) {
            }
        });

This all works just fine, when I put a break point on the server side it hits, but for some odd reason I after the PageMethod returns, I get the error call back of the ajax call never success! 一切正常,当我在服务器端放置一个断点时,它会命中,但是由于某种奇怪的原因,在PageMethod返回之后,我收到了错误调用ajax的调用,但从未成功! Any ideas. 有任何想法吗。

I cant use a script manager on this one! 我不能在这个上使用脚本管理器! I open to any cross browser solution!. 我向任何跨浏览器解决方案开放!

I used your code and am having no issues. 我使用了您的代码,没有任何问题。 Here is my exact code: 这是我的确切代码:

WebForm1.aspx WebForm1.aspx

<head runat="server">
<title></title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
</form>

<script>
    $.ajax({
        type: "POST",
        url: "/WebForm1.aspx/GetInt",
        data: "{id:'1'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            alert("SUCCESS: " + msg.d);
        },
        error: function (err) {
            alert("FAILURE");
        }
    });
</script>
</body>
</html>

WebForm1.aspx.cs WebForm1.aspx.cs

using System.Web.Services;


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

    }

    [WebMethod(true)]
    public static int GetInt(int id)
    {
        return 10;
    }
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM