N
If the site is not of the same domain it will be necessary to use this code at the top of the file.PHPheader('Access-Control-Allow-Origin: *'); //Qualquer site
header('Access-Control-Allow-Origin: http://site.com'); //Especificar os sites
To return on Json would be that wayPHPecho json_encode("teste");
ResultsYou did.To generate a filePHP$string = "minha string";
$fp = fopen('arquivo.json', 'w');
fwrite($fp, json_encode($string));
fclose($fp);
For your news you should bring your news and structure into an array and then print using json_encodeFictitious example of an array with the news:PHP$noticias = array(
array(
"titulo" => "noticia 1",
"corpo" => "corpo da noticia 1",
"data" => "02/07/2014"
),
array(
"titulo" => "noticia 2",
"corpo" => "corpo da noticia 2",
"data" => "02/07/2014"
),
array(
"titulo" => "noticia 3",
"corpo" => "corpo da noticia 3",
"data" => "02/07/2014"
),
array(
"titulo" => "noticia 4",
"corpo" => "corpo da noticia 4",
"data" => "02/07/2014"
)
);
echo json_encode($noticias);
Results[{"titulo":"noticia 1","body":"body of the news 1","data":"02/07/2014"},{"titulo":"new 2","body":"body of the news 2", "data":"02/07/2014"},{"titulo":"noticia 3", "body":"And the treatment of this Json can be done with JqueryJquery$(function(){
var jsonString = [{"titulo":"noticia 1","corpo":"corpo da noticia 1","data":"02/07/2014"},{"titulo":"noticia 2","corpo":"corpo da noticia 2","data":"02/07/2014"},{"titulo":"noticia 3","corpo":"corpo da noticia 3","data":"02/07/2014"},{"titulo":"noticia 4","corpo":"corpo da noticia 4","data":"02/07/2014"}];
$.each(jsonString, function(i, item){
$('.noticias').append("<li>"+ item.data +" - " +item.titulo + "</li>");
});
});
Obviously this json would be recovered with a $.get or $.post and will be treated at the site that should stay on the site. http://jsfiddle.net/dieegov/Hxqq9/