0

I have a php file which contains only JSON data(print_r($json)).I want to return this JSON data in AJAX success function.All the questions and tutorials are about a specific data returning,so I can't find a solution for having a return of all JSON data: Here's the code(in jQuery):

$.ajax({
    type        : 'POST',
    url         : 'https://example.com/api',
    contentType: 'application/json',
    data        : json,
    dataType: 'json',
    success: function(data){

/////$("body > .container").html(html);
   ///// var data = JSON.parse(html.data);
       //// alert(data[0]);
   //// var json = $.parseJSON(data); 
      //// alert(json.html); 
}
})
skyphoto
  • 15
  • 4
  • Post youur JSOn file also – kedar sedai Apr 20 '20 at 20:18
  • You can find the possible solutions here: https://stackoverflow.com/questions/19155192/jquery-ajax-call-to-php-script-with-json-return. and https://stackoverflow.com/questions/44123469/return-json-data-to-ajax-call – Ns789 Apr 20 '20 at 20:20
  • You cannot 'return' any data retrieved by an asynchronous request. See the duplicate I marked for more information and how to correctly work with the async pattern – Rory McCrossan Apr 20 '20 at 20:30
  • @RoryMcCrossan OK.it means that the non-asynchronous request will reload the page? – skyphoto Apr 20 '20 at 20:37

0 Answers0