JSON Data Return

0

I'm performing a simple data return on a Jquery function. However, the error message is displayed. Follow code

JSON:

<?php 
                 header('Content-Type: application/json');
                 $dados = "Meus Dados";
                 echo json_encode($dados, JSON_PRETTY_PRINT);     
?>

Jquery:

function carregarJson(){
 $.ajax({
      url: "json.php",
      dataType: 'json',
      success: function(data){
        alert(data);   
      },
      error:function(){
        alert("erro");
      }   
    }); 

  }
    
asked by anonymous 12.07.2016 / 14:50

1 answer

1

Simple function to return data with Json

JSON:

<?php 
                 $dados = "Meus Dados";
                 echo json_encode($dados, JSON_PRETTY_PRINT);     
?>

Jquery:

$.ajax({
      url: "inc/json.php",
      dataType: 'json',
      contentType: "application/json; charset=utf-8",
      success: function(data){
        alert(data);   
      },
      error:function(){
        console.log(data);
      }   
    }); 
    
12.07.2016 / 15:06