I generate a list of objects in a json file using PHP and then i used jQuery to get data from it
$.ajax({
url: url,
method: "get",
dataType: "json"
}).done(function (data) {
for(var i=0; i < data.length; i++){
document.getElementById("id01").innerHTML = data[i].Kategorianimi;
}
}).fail(function () {
document.getElementById("id01").innerHTML = "cant get json";
})
});
It worked ok in localhost but when i give a external host link to the url, it not work. Is there anyone has same issue with me and could you guy show me how to fix it? thanks.
When i add a header like this, then my JSON data was error
<?php
require_once "../pdo/kategoriaPDO.php";
header('Access-Control-Allow-Origin: *’);
/**
* Created by PhpStorm.
* User: dinhthinh
* Date: 27/11/16
* Time: 14:07
*/
$katepdo = new KatePDO();
$json = str_replace("\u0000","",json_encode($katepdo->listaKaikkiKategoriat(), true));
echo stripcslashes($json);