how to access an array within a json php to javascript/jquery Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of how to access an array within a json php to javascript/jquery without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I have this function in php

$everything= array($ary);
$response = (json_encode(array('code'=>'0','id'=>$id,'usr'=>$usr, 'everything'=>$everything)));

how can i access this using javascript/jquery.I have this at the moment.

javascript

 websocket.onmessage = function(ev) {
   received = JSON.parse(ev.data);
   var everything = received.everything;
 };

I am able to get all data except for the varible $everything how can I pass it from php and retrive it over in javascript.

Answer

a better way to do this is to use the implode function in php to convert the arrays in to strings and then pass it

$everything= array($ary);
 ConvertEverything = implode(' ',$everything);
$response = (json_encode(array('code'=>'0','id'=>$id,'usr'=>$usr, 'everything'=>$ConvertEverything )));

JavaScript

 websocket.onmessage = function(ev) {
   received = JSON.parse(ev.data);
   var everything = received.everything;
 };
We are here to answer your question about how to access an array within a json php to javascript/jquery - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji