").autocomplete({ source: function (request, response) { $.ajax({ type: "POST", url: 'EMR" /> ").autocomplete({ source: function (request, response) { $.ajax({ type: "POST", url: 'EMR" /> ").autocomplete({ source: function (request, response) { $.ajax({ type: "POST", url: 'EMR"/>

Web Method not called in ajax aspx web form

272 Views Asked by At

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?

1

There are 1 best solutions below

4
शेखर On

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.