How to convert the returned php array data in js

there is an A.php file on the server. Do curl to access the B.php of other addresses to retrieve data. The array is returned by print_r ($array) in B.php, and the array of B.php is read by A.php through curl. The result of local C.js file accessing A.php on the server is as follows:

datastringjsarray

A, B, CC.js

A.php:

clipboard.png

Thank you.

Mar.06,2021

generally php uses echo json_encode ($data); to return a string in json format).

if js uses a modern browser, just use var json=JSON.parse ($jsonstr);).

in addition, eval (); is not recommended in js
if the browser needs to be compatible with older versions, you can search the js json library on the Internet.


this print_r is only output according to PHP format. You need to find a general data format to transmit data. For example, if you use a lot of data here, you can also use json, xml. If PHP sends json, change print_r ($array) to echo json_encode ($array);

).

so that the json format data obtained by js can be transferred


php and js data transfer generally converts array to json format string output. After js uses ajax to get jsondata,
var arr = eval ('('+ jsondata+')'); / / get the array arr [1] arr ['name'] so call

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e9ce4d-1912.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e9ce4d-1912.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?