我正在尝试在我的neatbeans软件中使用JavaScript和JSON在服务器上获取.php文件。我是一个乞讨者,我没有找到任何解决方案。
我在开发者工具中得到了这个错误:
CORS策略阻止了从源'http://localhost:8084‘对位于'http://evercodeplus.com/get_products.php’的XMLHttpRequest的
访问:请求的资源上不存在' Access -Control-Allow- origin‘标头。
我也不知道为什么pro.insertAdjacentHTML不能工作。
我见过人们提到json_encode
,但我不知道如何使用它。
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');
}
https://stackoverflow.com/questions/56512091
复制相似问题