开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜