如何从URL获取数据到ReactJS。
网址具有以下类型:http : //www.domain.com/api/json/x/a/search.php?s=category
如果在浏览器中键入,则会显示一个json对象。
如何将其加载到ReactJS。
首先,我以:
const dUrl = "http://www.the...."; console.log(dUrl);
但是很明显,它显示的是url而不是内容(我可以过滤它-这只是将其加载到我不知道的对象中的第一步)
编辑:我宁愿不使用jQuery。
编辑:使用提取进行API调用。
fetch(http://www.example.com/api/json/x/a/search.php?s=category) .then(response => response.json()) .then((jsonData) => { // jsonData is parsed json object received from url console.log(jsonData) }) .catch((error) => { // handle your errors here console.error(error) })
在所有现代浏览器中均可使用访存。