简体   繁体   中英

ajax POST problem - 500 internal server error

I have problem when I running my project. When I run the project I get 500 internal server.

My code:

Client.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; }
       
    }

In Regrestion.aspx file when the function Regrestion works - then I get always 500 error

 <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>

Code behind Registretion.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;
        }

500 internal server error means that server responded with an error. There is some problem in backend (your server-side).

It has nothing to do with JavaScript or AJAX. It is also not a connection issue.

Looking at your code: Don't you have a missing } bracket at the end of your Registretion.aspx.cs file?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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