Patrickkx Patrickkx - 1 month ago 9
JSON Question

PHP: Export a JSON file and catch it by JS

Got a php code:

<?php
$date = date("Y/m/d");
echo json_encode($date);
?>


It exports a json file. But then, I wanna catch it by JS:

$.get("/your/url").done(function(data){
});


But my problem is - how can I know where the JSON file was saved (if it even was saved)?

Does the
echo json_encode($date)
exports a json file to somewhere? Or echo has nothing to do with that?

Thanks for any further help.

Edit: Anybody can help me?

Answer

Your are doing correctly in php side but in jquery side i dont know if $.get().done() works or not

i have used it by this way and its working fine

$.getJSON( "url/yoururl", function( data ) { 
  console.log(data);

});

You can also use

$.ajax({
method:GET,
url:'url/yoururl',
success:function(data){
   console.log(data);
}
});

console.log(data) will return date which you have exported from php