Why does it flag error "500 internal server error", in an Ajax call?

0

I am trying to make a call Ajax, but it marks me 500 internal server error, I could not find where the error is, here I leave my code:

debugger
            $("#NotificaSolo").click(function () {
                debugger

                var table = $('#Notificar').DataTable();
                var ids = $.map(table.rows('.selected').data(), function (item) {
                    return item[3]
                });
                $.ajax(
                    {
                        url: "Formularios.aspx/EnviarCorreo",
                        data: JSON.stringify(ids),
                        dataType: "json",
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        success: function (response) { alert(response.d); },
                        error: function (result) {
                            alert("ERROR " + result.status + ' ' + result.statusText);
                        }
                    });
                return ids;
            });

and my WebMethod

[System.Web.Services.WebMethod()]
        public string EnviarCorreo(string ids)
        {
            XmlSerializer xml_serializer = new XmlSerializer(typeof(cLogin));
            StringReader string_reader = new StringReader(CookieUtils.LeeValorCookie(System.Web.Configuration.WebConfigurationManager.AppSettings["nombreCookie"]));
            cLogin myLogin = (cLogin)xml_serializer.Deserialize(string_reader);
            string_reader.Close();
            try
            {
                String regresa = String.Empty;
                String[] valores = ids.Split(',');

                var ahora = DateTime.Now;
                var send = new SendGrid2(string.Format("Aviso {0:dd/MM/yyyy}", ahora));
                for (int i = 0; i < valores.Length; i++)
                {
                    send.AgregarDestinatario(valores[i]);
                    send.De = new EmailAddress("sistema@checkapp", "CheckApp web");
                    //send.De = new EmailAddress(cuenta, "CheckApp web");
                    send.AgregarLinea("Tiene una encuesta pendiente");
                    send.AgregarLinea("No responder, mensaje enviado automáticamente");
                    bool enviado = true;
                    if (enviado == send.EnviarMensaje())
                    {
                        string mensaje = string.Empty;
                        //mensaje = "<script>javascript:alert(' No se encontraron datos');</script>)";
                        clsCtaMail cuenta = new clsCtaMail();
                        //                    cuenta.direccion = txtUser.Text;
                        cuenta.activa = true;
                        cuenta.idUsuario = myLogin.UsrId;
                        cuenta.empresa = myLogin.EmpId;
                        cuenta.GuardaCuenta();
                    }
                    else
                        enviado = false;
                }
                return  "Enviado";
            }
            catch (Exception ex)
            {
                ex.ToString();
                return "Fallido";
            }
        }
  

jquery.min.js: 4 POST    link 500 (Internal   Server Error)

    
asked by Oscar Navarro 10.01.2018 в 21:00
source

1 answer

1

All WebMethod included in an aspx must be declared as static

[System.Web.Services.WebMethod()]
public static string EnviarCorreo(string ids)

If you do not declare yourself that way, it will not be accessible from your call ajax

    
answered by 10.01.2018 / 21:44
source