Ajax调用在Asp.Net Web应用程序中返回500错误

时间:2015-09-30 09:18:39

标签: c# jquery asp.net ajax

我尝试在我的网络应用程序中向服务器发送Ajax请求,但它总是返回500 internal server error

以下是我的代码

Test.aspx文件

<script src="assets/plugins/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
    var postdata = JSON.stringify(
                        {
                            "Name": "rakeev",
                            "Age": "28"
                        });;

    function testjson() {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "test.aspx/GetId",
            data: "{json: '" + postdata + "'}",
            dataType: "json",
            success: function (result) { alert("c"); },
            error: function (xhr, ajaxOptions, thrownError) {
                alert(xhr.status);
                alert(thrownError);
            }
        });
    }
</script>
</head>
<body>
<form id="form1" runat="server">
    <input type="button" value="text" onclick="testjson()" / >   
</form>
</body>

test.aspx.cs

namespace testApp
{
public partial class test : System.Web.UI.Page
{
    [System.Web.Services.WebMethod]
    public static Int64 GetId(string data)
    {
        using (JoyRydeAnalysis.Data.joyryde_analyzerEntities context = new JoyRydeAnalysis.Data.joyryde_analyzerEntities())
        {
            var id = context.tbl_item_list.Where(x => x.TXT_ITEM_NAME == data).Select(x => x.LNG_ITEM_ID).FirstOrDefault();
            return id;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}
}

是否有其他方法用于在Asp.net webApplication中发送AJAX调用?

0 个答案:

没有答案