How to access AJAX returned data with PHP?

I hava data structure like this which is then returned to another file with AJAX:

$data = array();
   $data['message'] = "You are searching: $domain!";
   $data['domain:name'] = "domain.tld";
   $data['domain:registrar'] = "Registrar Ltd.";
   $data['domain:creation'] = "2015-26-05";
   $data['domain:expiry'] = "2016-26-05";
   $data['ns'] = "ns1.somedns.tld";
   $data['owner']['name'] = "Owner Name";
   $data['owner']['type'] = "Org";
   echo json_encode($data);

That data is then append to html with AJAX like this:

success: function (data) {
                dataType: 'json',

Now I want to pass that returned JSON object to PHP variable, so I can easy manipulate date with PHP. How do I do that? Or is best practice to do it with JS? Basically I want to print every key:pair value, so maybe for in is good choice.

And, I am not sure, should, or must I echo data in my script so AJAX can pick it up, or can I just pass data to variable and then fetch it in AJAX?

Source: ajax

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.