简体   繁体   中英

How can I get the data transfered data from jQuery.getJSON within the PHP file?

I have a Javascript variable whatToRefresh which is defined in this way:

var whatToRefresh = 
{
    "online" : true,
    "running" : false,
    "detail" : 0
};

This variable is used within a getJSON to tell the php file what data are requested:

$.getJSON("scripts/php/RequestData.php", whatToRefresh, function(data) { PopulateData(data); });

Now I need the data within the PHP file but this returns all the time null:

$requestData = json_decode(($_GET['data']), true);

How can I access this data within php?

just access $_GET['online'], $_GET['running'], $_GET['detail']. try to see that - var_dump($_GET);

Where you're getting confused is, the $.getJSON method.

JSON is not being sent to the server, so you do not need to decode it with json_decode .

This jQuery method is just sending an HTTP get request, with a query string that has your variables in it. The $.getJSON method expects to see a JSON response from the server, hence the json in the name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM