首页 > 解决方案 > ajax POST 问题 - 500 内部服务器错误

问题描述

我在运行项目时遇到问题。当我运行该项目时,我得到 500 个内部服务器。

我的代码:

客户端.cs

public class Client
    {
        public Client(string firstName, string id, string lastName)
        {
            FirstName = firstName;
            LastName = lastName;
            Id = id;
        }
        [JsonProperty("id")]
        public string Id { get; set; }
        [JsonProperty("first_name")]
        public string FirstName { get; set; }
        [JsonProperty("last_name")]
        public string LastName { get; set; }
       
    }

在 Regression.aspx 文件中,当函数 Regression 工作时 - 然后我总是得到 500 错误

 <script type="text/javascript" language="javascript">
        function Regrestion() {

            //get data by document.getElementById...
            var d = {
                first_name: firstName,
                id: id,
                last_name: lastName
            }
            $.ajax({
                url: 'Registretion.aspx/AddNewClient',
                method: "POST",
                contentType: "application/json; charset=utf - 8",
                dataType: 'json',
                data: JSON.stringify(d),
                success: function (flights) {
                    alert("succ");
                }, error: function (error) {
                    alert("error");
                }
            });
        }
    </script>

Registry.aspx.cs 背后的代码

 public partial class Registretion : System.Web.UI.Page
    {
          
        [System.Web.Services.WebMethod(EnableSession = true)]
        [System.Web.Script.Services.ScriptMethod]
        public static Client AddNewClient(Client c)
        {
          //more  code
            return c;
        }

标签: javascriptajaxposthttp-status-code-500

解决方案


500 internal server error表示服务器响应错误。后端(您的服务器端)存在一些问题。

它与 JavaScript 或 AJAX 无关。这也不是连接问题。

查看您的代码:您的Registretion.aspx.cs文件末尾是否缺少}括号?


推荐阅读