-1

Here is my ajax request:

$("#<% =txtDiagnosisData.ClientID %>").autocomplete({                
                source: function (request, response) {
                    $.ajax({
                        type: "POST",
                        url: 'EMR.aspx/SearchDiagnosis',
                        contentType: "application/json;charset=utf-8",
                        dataType: "json",
                        success: function (data) {
                          //  response(data.d);
                            alert("success");
                        },
                        error: function (result) {
                            alert("error");
                        }
                    });
                }
            });

Here is my function:

[WebMethod]
public static List<string> SearchDiagnosis()
{
    return new DataAccess().GetDiagnosis();
}

My method is not called from ajax, it always goes to the error part How to solve this?

शेखर
  • 17,412
  • 13
  • 61
  • 117
Subrata P
  • 15
  • 5
  • Note that if you are using session then this may break. Use attribute like `[WebMethod(enableSession: true)]` and see if it works. And put the error what you are getting. – शेखर Nov 23 '20 at 12:56

1 Answers1

0

There could be an issue that you might be using Session variables inside you web method directly or indirectly.

Somewhere in the function DataAccess().GetDiagnosis();

In that case use attribute like [WebMethod(enableSession: true)] in stead of [WebMethod] Also try to get the error by implementing error properly like below

 error: function (jqXHR, textStatus, errorThrown) {
              if (jqXHR.status == 500) {
                  alert('Internal error: ' + jqXHR.responseText);
              } else {
                  alert('Unexpected error.');
              }
          }

Ref : jQuery ajax error function and see what error exactly you are getting.

शेखर
  • 17,412
  • 13
  • 61
  • 117
  • its showing now Unexpected error,but my web method is still not calling – Subrata P Nov 24 '20 at 07:35
  • @SubrataP can you post the error in you question. Put the values of jqXHR.responseText and all other parameters as well. Also try to call that method from browser directedly. Or use postman to create request. – शेखर Nov 24 '20 at 08:06
  • after enabling its also not working,and the error is is : unexpected error – Subrata P Nov 25 '20 at 09:20
  • I called it from postman,and the status is 200 Ok,but its returning an html – Subrata P Nov 28 '20 at 05:07