Ver Mensaje Individual
  #7 (permalink)  
Antiguo 14/03/2014, 11:20
Avatar de satjaen
satjaen
 
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 8 meses
Puntos: 10
Respuesta: Enviar datos recogidos de json

Cita:
Iniciado por Alexis88 Ver Mensaje
Si es un y sólo un objeto JSON, accede a sus atributos sin usar índices.

Código Javascript:
Ver original
  1. var json = {nombre: "Juan", edad: 20};
  2.  
  3. document.body.innerHTML += "Nombre: " + json.nombre + "<br />";
  4. document.body.innerHTML += "Edad: " + json.edad;

Resultado:

Código HTML:
Ver original
  1. Nombre: Juan
  2. Edad: 20

Saludos


Gracias Alexis, quieres decir así:

Código Javascript:
Ver original
  1. <script>
  2.  
  3.   $.ajax({
  4.              type: "GET",
  5.              url: "edit-total.php?tabla=1&id_aviso=" +id_aviso,
  6.                          dataType: "json",
  7.              beforeSend:function(objeto){
  8.                         $('#carga').css({display:'block'});
  9.             },
  10.                         complete:function(){
  11.                 $('#carga').css('display','none');
  12.                 },
  13.             })
  14.          success: function(data){
  15.                  var html_user ='' ;
  16.                  if(data.length > 0){
  17.                  $.each(data, function(i,item){
  18.  
  19.  html_user += '<td >'+item.descuento+'</td>';
  20.  html_user += '<td >'+item.pvp_total+'</td>';
  21.  html_user += '<td >'+item.iva+'</td>';
  22.  html_user += '<td >'+item.total+'</td>';
  23.  
  24.  
  25.  
  26. });
  27.  
  28.  
  29.  }
  30.  
  31.          var dataString =  
  32.  
  33.                     $.ajax({
  34.                     type: "POST",
  35.                     url: "insertar.php",  -------> Aqui hago el insert en la base de datos
  36.                     data: dataString,
  37.                     beforeSend:function(objeto){
  38.                     $('#carga').css({display:'block'});
  39.                     },
  40.                     complete:function(){
  41.                     $('#carga').css('display','none');
  42.                     },
  43.                     success: function(data) {
  44.  
  45.             }
  46.         });
  47.  
  48.    
  49.  
  50.   </script>



Pero como se haría el dataString ?

Podría ser ?:

Código Javascript:
Ver original
  1. var dataString = 'descuento='+item.descuento+'&pvp_total='+item.pvp_total+'&iva='+item.iva+'&total='+item.total;

Última edición por satjaen; 14/03/2014 a las 11:32