Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/11/2014, 18:55
joseberrocalobando
 
Fecha de Ingreso: mayo-2014
Ubicación: Liberia, Guanacaste, Costa Rica
Mensajes: 17
Antigüedad: 9 años, 10 meses
Puntos: 0
Pregunta problema al llamar metodos vb desde JS

buenas gente tengo un problema, resulta ser que necesito hacer el llamado a un metodo en Vb desde JavaScript pero depende de la manera en como lo haga este no funciona, voy a poner los codigos

Código Javascript:
Ver original
  1. var params = "{ Nombre: '" + Objeto + "'}";
  2.                              
  3.  PageMethods.AgregarChofer(params);  
  4. // este funciona, va al lado servidor y todo perfecto

pero usando Ajax me da un codigo de error 500, el cual no entiendo la verdad
Código Javascript:
Ver original
  1. $.ajax({
  2.                     type: "POST",
  3.                     contentType: "application/json; charset=utf-8",
  4.                     url: "Realizar.aspx/AgregarChofer",
  5.                     data: params,
  6.                     dataType: "json",
  7.                     success: function (data) {
  8.                         alert('Entro');
  9.                         $("#gvSeleccionados").empty();
  10.  
  11.                         if (data.d.length > 0) {
  12.                             $("#gvSeleccionados").append("<tr> <th> </th> <th>Nombre</th> </tr>");
  13.                             for (var i = 0; i < data.d.length; i++) {
  14.                             alert(data.d[i].Nombre)
  15.                                 $("#gvSeleccionados").append("<tr><td>" +
  16.                             "<a href=\" \" class=\"Iconos\"> <img " +
  17.                             "src=\"images/user_remove.png\" " +
  18.                             "onclick=\"QuitarChofer(this)\" alt=\"Agregar Chofer\" " +
  19.                             "/></a>" + "</td> <td>" +
  20.                             data.d[i].Nombre + "</td></tr>");
  21.                             }
  22.                         }
  23.                     },
  24.                     error: function (result) {
  25.                         alert("Error al llenar el grid");
  26.  
  27.                     }
  28.                 });

el metodo en la parte servidor es el siguiente:
Código ASP:
Ver original
  1. <System.Web.Services.WebMethod()> _
  2.     Public Shared Function AgregarChofer(data As Object) As pChofer()
  3.         Dim Choferes As New List(Of pChofer)()
  4.         Dim posible As Boolean = True
  5.  
  6.         Dim Json As String = data
  7.         Dim ser As JObject = JObject.Parse(Json)
  8.         Dim datos As List(Of JToken) = ser.Children().ToList
  9.  
  10.         For Each item As JProperty In datos
  11.             item.CreateReader()
  12.             Select Case item.Name
  13.                 Case "Nombre"
  14.                     If Lista.choferes.Count > 0 Then
  15.                         For Each value In Lista.choferes
  16.                             If value = item.Value Then
  17.                                 posible = False
  18.                                 MsgBox("Ese chofer ya ha sido agregado", MsgBoxStyle.OkOnly, "No se pudo agregar")
  19.                                 Return Nothing
  20.                                 Exit For
  21.                             Else
  22.                                 Lista.choferes.Add(item.Value)
  23.                             End If
  24.  
  25.  
  26.                         Next
  27.                     Else
  28.                         Lista.choferes.Add(item.Value)
  29.                     End If
  30.  
  31.             End Select
  32.         Next
  33.  
  34.  
  35.         For Each value In Lista.choferes
  36.             Dim oChofer As New pChofer
  37.             oChofer.Nombre = value.ToString
  38.             Choferes.Add(oChofer)
  39.         Next
  40.  
  41.         Return Choferes.ToArray
  42.     End Function

Agradeceria cualquier ayuda que me puedan dar, y de antemano muchas gracias