0

I have a php file where I retrieved data from the server. I want to parse the data into my pure Javascript file in order to store it in an array.

This is my php code:

$dir = "images";
$folders = array_diff(scandir($dir), array('..', '.'));
$folders = array_values($folders);
print_r($folders);

$encodedArray = json_encode($folders);

print_r($encodedArray);

I want to send over the encodedArray to my pure Javascript file as I want to put them into an array to use. Is it possible to send it to a pure JS file?

2
  • Yes, use an HTTP request (fetch / Axios / XMLHttpRequest) to load the PHP script that outputs JSON. Commented Apr 7, 2021 at 1:26
  • What you are asking has nothing to do with what “parsing” actually means. Commented Apr 7, 2021 at 8:15

1 Answer 1

2

you can print your variable JSON "echo $encodedArray", and you can use fetch to get data from your url. ex: fetch("https://getdatafromserver.php");

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.