0

When I am calling server method from AJAX call at that time showing 500 internal server error. And this error also happens sometimes only, while sometimes it is working fine.

I am really confused that what is going on that it is sometimes working and sometimes not working. In fact I didn't change anything after working the code but when I check second day it is coming this type of error.

Here is my code

<input type="button" id="btn_save" value="Save" class="button" />

$(document).on("click", "#btn_save", function (e) {
                            $.ajax({
                                type: "POST",
                                url: "schoolregistration.aspx/EntrySave",
                                data: JSON.stringify({ schoolName: $('#txt_schoolname').val() }),
                                contentType: "application/json; charset=utf-8",
                                dataType: "json",
                                success: OnSuccess,
                                failure: function () {
                                    document.getElementById("txt_schoolname").value = "";
                                    alert("Error! Try again...");
                                }
                            });
                        });

                        function OnSuccess(response) {
                            document.getElementById("txt_schoolname").value = "";
                            alert(response.d);
                        }

[WebMethod]
    public static string EntrySave(string schoolName)
    {
               //Here is the code
    }

Sometimes working fine but sometimes not coming call in this entrysave method.

halfer
  • 19,824
  • 17
  • 99
  • 186
s.k.Soni
  • 1,139
  • 1
  • 19
  • 37
  • 1
    this type of issues is coming in my code also. Today is everything is alright but tomarrow it showing the 500 internal server error.....I am also thinking that only what is going on...........??!!!!!! – karan Jul 08 '17 at 10:14
  • 500 indicates a server side error. You need to debug your c# code or try to find/read the Exception being thrown server side. – Igor Jul 08 '17 at 10:17
  • Please read carefully my question. @Igor I have described that method is not calling from ajax i.e. means so how can I debug......???? – s.k.Soni Jul 08 '17 at 10:19
  • Possible duplicate of [Ajax - 500 Internal Server Error](https://stackoverflow.com/questions/4789613/ajax-500-internal-server-error) – Igor Jul 08 '17 at 10:31
  • Nope it is not possible heading is almost but matter is different. If you know answer then please comment else np. – s.k.Soni Jul 08 '17 at 10:33

1 Answers1

0

try this:

 $.ajax({
                                type: "POST",
                                url: "schoolregistration.aspx/EntrySave",
                                data: { "schoolName": $('#txt_schoolname').val() },
                                contentType: "application/json; charset=utf-8",
                                dataType: "json",
                                success:function (data) {alert('ok');},
                                 error: function () {alert('error');}
                            });