Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/03/2010, 12:35
Avatar de jorgelig
jorgelig
 
Fecha de Ingreso: septiembre-2004
Ubicación: Chapis Data Center
Mensajes: 27
Antigüedad: 19 años, 7 meses
Puntos: 0
[Solucionado]Error undefined al comunicar Jquery con Webservice

Buenos dias, le di una rapida búsqueda y el [URL="http://www.forosdelweb.com/f29/no-puedo-hacer-post-con-jquery-hacia-web-service-679481/"] único post que encontre parecido[/URL] a mi pregunta no esta respondido, por lo que me animo a postear mi pregunta.

Hasta ahora había estado usando los componentes AJAX directamente con webservice y ningun problema, hace un par de semanas estoy intentando optimizar mas la aplicacion usando jQuery directamente con los webservice. Encontre varias guias pero la que me ah parecido mas completa es [URL="http://www.mikesdotnetting.com/Article/96/Handling-JSON-Arrays-returned-from-ASP.NET-Web-Services-with-jQuery"]esta[/URL], y la estoy intentando seguir, pero al momento de llamar la funcion de jquery que se comunica con el webservice truena y en el error solo dice undefined, eh estado buscando posibles soluciones pero hasta ahora nada.

Mi ASPX es este:
Código:
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default3.aspx.vb" Inherits="Default3" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <script type="text/javascript">
  function prueba(){
      $.ajax({
      type: "POST",
      url: "WS_Productos.asmx/GetProductosNombreID",
      //beforeSend: function(xhr) {xhr.setRequestHeader("Content-type", "application/json; charset=utf-8");},      
      //data: "{ 'nombre':"+"'" + $get('<%= txtbuscaidproducto.ClientID %>').value + "'}",
      //data: "nombre=jorgelig",
      data: "{nombre: " + $get('<%= txtbuscaidproducto.ClientID %>').value + " }",
      contentType: "application/json; charset=utf-8",
      dataType: "json"  ,
      success: function(response) {
      alert($get('<%= txtbuscaidproducto.ClientID %>').value);
      var productos = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
      $('#output').empty();
      for(var i=0;i< productos.length;i++){
        $('#output').append('<p>' + productos[i].Id_producto + ', ' + productos[i].Nombre + ', ' + productos[i].Precio + '</p>')
      }
      },
      error: function(msg,status,error) {
      $('#output').text(msg);
      //alert(msg.toString );
        //$('#output').html('ERROR '+ msg.valueOf );
      }
    });
  }
</script>
<asp:TextBox ID="txtbuscaidproducto" runat="server" Width="274px"></asp:TextBox>
<input id="btn_htmlfiltrar" class="cssboton" type="button" 
                  value="FiltrarAJax" onclick="prueba()" />
                  <div id="output">PRUEBA</div>
</asp:Content>
El Webservice que tengo programado es este:
Código:
<%@ WebService Language="VB" Class="WS_Productos" %>

Imports System.Web
Imports System.Web.Services.Protocols
Imports System.Web.Services
Imports System.Web.Script.Services
Imports System.Web.Script.Serialization
Imports System.Collections.Generic

<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WS_Productos
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function GetProductosNombreID(ByVal nombre As String) As List(Of Normay.ElArco.Source.DataBase.Producto.Producto)
        Dim Productos As New List(Of Normay.ElArco.Source.DataBase.Producto.Producto)
        
        Dim ent As New Normay.ElArco.Source.DataBase.ConsultasGenerales
        Dim dr As MySql.Data.MySqlClient.MySqlDataReader
        Dim sql As String
        
        sql = "SELECT id_producto,nombre,costo,precio FROM Producto WHERE nombre LIKE '%" & nombre & "%';"
        dr = ent.LlenaDataReader(sql)
        For i = 0 To dr.FieldCount
Productos.Add(New Normay.ElArco.Source.DataBase.Producto.Producto(dr("id_producto"), dr("nombre"), dr("costo"), dr("precio")))
     Next
        ent.CerrarConeccion()
        dr.Close()
        Return productos
    End Function

Última edición por jorgelig; 10/03/2010 a las 11:28 Razón: Solucionado