I am trying to get a .php file on a server in my neatbeans software using JavaScript with JSON. I am a begginer and I am not finding any solution.
I get this error in developers tool:
Access to XMLHttpRequest at 'http://evercodeplus.com/get_products.php' from origin 'http://localhost:8084' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Also I don't know why the pro.insertAdjacentHTML is not working.
I have seen people mentioning json_encode
, but I don't know how to use it.
xmlhttp.open('GET', 'http://evercodeplus.com/get_products.php' , true);
xmlhttp.onload = function (){
var ourData = JSON.parse(xmlhttp.responseText);
showHTML(ourData);
};
xmlhttp.send();
};
function showHTML(data)
{
var htmlString = "";
for(i=0; i<data.length; i++)
{
htmlString += "<ul>" + data[i].name + ".</ul>";
}
document.getElementById("product").innerHTML=htmlString;
pro.insertAdjacentHTML('beforeend','htmlString');
}