Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/10/2012, 10:46
domanion
 
Fecha de Ingreso: mayo-2009
Mensajes: 106
Antigüedad: 15 años
Puntos: 1
Manejar un solo tipo en consulta Ajax

Hola me estoy basando en este ejemplo http://stackoverflow.com/questions/1...output-in-ajax

y me ha funcionado perfectamente, lo que pasa es que cuando envio un solo (en este caso producto) en lugar de una lista no funciona.

lo que hago en el js poner:

Código Javascript:
Ver original
  1. $.get('hola?do=dos', function(responseJson) { // Execute Ajax GET request on URL of "someservlet" and execute the following function with Ajax response text...
  2.                         //$('#div_respuesta').text(responseText);         // Locate HTML DOM element with ID "somediv" and set its text content with the response text.
  3.                         //$('#usuario_input').val(responseText);
  4.                         var $table = $('<table>').appendTo($('#div_respuesta')); // Create HTML <table> element and append it to HTML DOM element with ID "somediv".
  5.                         //$.each(responseJson, function(index, producto) {    // Iterate over the JSON array.
  6.                             $('<tr>').appendTo($table)                     // Create HTML <tr> element, set its text content with currently iterated item and append it to the <ul>.
  7.                             .append($('<td>').text(responseJson.id))        // Create HTML <td> element, set its text content with id of currently iterated product and append it to the <tr>.
  8.                             .append($('<td>').text(responseJson.marca))      // Create HTML <td> element, set its text content with name of currently iterated product and append it to the <tr>.
  9.                             .append($('<td>').text(responseJson.costo));    // Create HTML <td> element, set its text content with price of currently iterated product and append it to the <tr>.
  10.                         //});
  11.                     });

los nombres como ven los cambie y antes de aplicar los comentarios si funcionaba, el principal cambio que hize fue omitir el foreach y "tomar" directo los valors de la respuesta, pero aun nada.

muchas gracias por sus respuestas
__________________
VivaMéxico