1

$.getJSON might be misleading, but what I want to do is get JSON from a url via a PHP file.

var url = "https://script.google.com/macros/s/XXXXXXXXXX/exec?action=read";
$.getJSON(url, function (json) {
//DO SOMETHING WITH THE DATA
}

This works fine in javascript. When I google get JSON from url maybe it's because I'm learning PHP but I can't seem to find an answer that works. Or when I google $.getJSON I get people trying to get Json from a PHP file.

All my data is stored via a googlesheet that I access by calling google script and it sends it back and I can take the information I want e.g

json.records[0].NAME;

I want to pass some data to a PHP file that I can't fathom how to do that.

Any help would be greatly appreciated.

  • Research how to get the _content_ returned by a URL using PHP, decode the recieved text as JSON afterwards. – CBroe Jun 02 '20 at 09:20

1 Answers1

2

It's simple as js:

$content = file_get_contents('https://script.google.com/macros/s/XXXXXXXXXX/exec?action=read');
$data = json_decode($content); // return object
$data = json_decode($content, true); // return array
bangnokia
  • 259
  • 2
  • 9
  • I was just about to respond to CBroe that return content from URL helped in my google search, but you've also answered what I've just found the answer for aswell. Thank you both. ``` $url = "https://script.google.com/macros/s/xxxxxxx/exec?action=read"; $json = file_get_contents($url); $jsonData = json_decode($json, true); echo $jsonData['records'][0]['NAME']; ``` – Scott McGee Jun 02 '20 at 09:34