Send json atraves from ajax to sockect.io

0

I tried to send an array through ajax to a server which will send it to all connected users but send it empty, if it was sent as normal, that is only the data if it is sent but in json mode and I do not want it to send the array Who is this caul here I leave my code to understand me better hopefully and can help me

this is the callback that I sent to ajax from insert_messages.php

$data[]=array('number_m' => $count_msg2 ,'my_session_id' => $yo , 'foto' => $picture,'mensajito' => $textoChat ,'userid' => $dato);

 echo json_encode($data);

then from ajax the following

 $.ajax({

        url:"insertar_mensajes.php",
        type:"GET",
        data:$(".formi").serialize(),
        datatype:"json", 

        success: function(data){
       //si mando solo el data si funciona y manda el json tal cual
      /*pero yo necesito desglosar ese json para mostrarlo en sus etiquetas 
       correspondientes*/
        socket.emit('notification',{

         mypic:      data[0].foto, 
         msgNotify:  data[0].number_m,
         mySession:  data[0].my_session_id,
         comentario: data[0].mensajito,
         myfriend:   data[0].userid });    


         }

      });

I send it empty to the nodejs server but if I just send data if I send it example

$.ajax({

        url:"insertar_mensajes.php",
        type:"GET",
        data:$(".formi").serialize(),
        datatype:"json", 

        success: function(data){

        socket.emit('notification',data);



         }

      });

from the nodejs server I send it as it should but nothing always tells me undefined in the label that I want to show it by not sending the json, example of the emit from the server nodejs

socket.on('notification', function(data) {
        console.log(data);
        io.sockets.emit('notification',{

            mypic: data.mypic, 
            msgNotify: data.msgNotify,
            mySession: data.my_session_id,
            comentario: data.mensajito,
            myfriend:   data.userid });

    });  

Any help or tips is grateful thanks!

    
asked by andy gibbs 28.05.2018 в 00:43
source

0 answers