1

I have a problem, I wrote a function for printing message data from a JSON file, but I do not know how to remove message data with specific id and reply on message to sender? Do I use only javascript or I have to use PHP? Can somebody help me?

My data.json file:

{
   "data":[
      {
         "id":"2146",
         "from":{
            "id":"234",
            "name":"Alan Ford"
         },
         "to":{
            "id":"4949",
            "name":"Eric Owens"
         },
         "type":"1",
         "replyto":"0",
         "date_sent":"1344359836",
         "date_read":"0",
         "subject":"test",
         "message":"test inbox",
         "message_formatted":"test inbox",
         "date_sent_formatted":{
            "id":1196,
            "timestamp":1344297600,
            "month":8,
            "day":7,
            "year":2012,
            "week":32,
            "dayid":3,
            "weekday":"Tue",
            "mname":"Aug",
            "formatted":"Aug 7, 2012"
         },
         "date_read_formatted":[

         ]
      },
      {
         "id":"2048",
         "from":{
            "id":"234",
            "name":"Alan Ford"
         },
         "to":{
            "id":"8110",
            "name":"Event"
         },
         "type":"1",
         "replyto":"0",
         "date_sent":"1343248577",
         "date_read":"0",
         "subject":"afd",
         "message":"asdfads",
         "message_formatted":"asdfads",
         "date_sent_formatted":{
            "id":1184,
            "timestamp":1343260800,
            "month":7,
            "day":26,
            "year":2012,
            "week":30,
            "dayid":5,
            "weekday":"Thu",
            "mname":"Jul",
            "formatted":"Jul 26, 2012"
         },
         "date_read_formatted":[

         ]
      }
    ]
}

My jquery file:

 $(document).ready(function(){

    $.getJSON('public/js/data.json', function(json){


        var msg = json.data

        for ( i = 0; i < msg.length; i++ ) {


                    var  content =  '<li>';
                         content += '<span class="left">' + msg[i].from.name +'</span>';
                         content += '<span class="right">'+ msg[i].date_sent_formatted.formatted +'</span>';
                         content += '<p>' + msg[i].subject + '</p>';
                         content += '<p>' + msg[i].message + '</p>';
                         content += '<button>Replay</button>';
                         content += '<button>Delete</button>';
                         content += '</li>';


                    $('.content').append(content);
        }

    });


});


function delete_message(id){


}

function reply_message(id, sender){

}
stori87
  • 19
  • 3
  • What are you actually trying to do? – An0nC0d3r Oct 24 '15 at 19:45
  • You have to use PHP or Other File Handling programming language to actually modify the file. And as for the Message Sending part you need server side programming language to perform that task too. – TipuZaynSultan Oct 24 '15 at 19:49
  • Welcome to SO. Please read [What topics can I ask about](http://stackoverflow.com/help/on-topic) and [How to ask a good question](http://stackoverflow.com/help/how-to-ask) – RiggsFolly Oct 24 '15 at 19:58
  • here's a fiddle of this question, just trying to help: http://jsfiddle.net/ar285p42/ OP, is the ouput ok? – GrafiCode Oct 24 '15 at 20:10
  • Yes, output is correct... – stori87 Oct 24 '15 at 20:45
  • @GrafiCodeStudio Yes, output is correct... but I have to use php and jquery, and i trying to figure out... this is just for my learning process :-) – stori87 Oct 25 '15 at 15:59
  • @stori87 here is an updated fiddle showing hot to remove ("delete") a message ( "
  • " ) from your list: http://jsfiddle.net/ar285p42/1/ does it help?
  • – GrafiCode Oct 25 '15 at 16:30
  • @GrafiCodeStudio Thank you, it help a lot! – stori87 Oct 25 '15 at 17:14