繁体   English   中英

ASP.NET + jQuery AJAX-出现500个服务器错误

[英]ASP.NET + jQuery AJAX - getting 500 server error

我想通过AJAX通过响应从jQuery调用ASP.NET函数。

我有文件Controll.aspx,其中包含JavaScript代码。 接下来,我有/Services/ControllService.asmx,函数在哪里,我想从js调用它。

js代码:

$(document).ready(function () {
    $('#btn_start').on('click', function () {
        $.ajax({
            type: "POST",
            url: "Services/ControllService.asmx/Start",
            data: {},
            dataType: "json",
            async: true,
            contentType: "application/json; charset=utf-8",
            success: function (response) {
                console.log(response);
            },
            error: function (err) {
                alert("Error:" + err.toString());
            }
        });

    });
});

但是我仍然收到错误500。

POST http://localhost:56000/Services/ControllService.asmx/Start 500 (Internal Server Error)
k.cors.a.crossDomain.send
n.extend.ajax

您有什么提示吗,例如在Web.config中需要设置什么?

非常感谢。

解决了:

1-我在ControllService.asmx.cs中将Start函数定义为静态。

2-我的数据配置错误。 它必须以相同的方式命名,例如“ sth”。

在javascript中,应为:

...
url: "Services/ControllService.asmx/Start",
data: JSON.stringify({ sth: "hahaha" }),
dataType: "json",
...

并在ControllService.asmx.cs->方法中启动

public string Start(string sth){}

非常感谢您的提示。

暂无
暂无

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

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