how to get the dataset from string?
javascript
Solution
You cannot parse Json from url .If you need data from URI do send an ajax call for that :- //Simple javascript example.
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var massive = JSON.parse(xmlhttp.responseText);
console.log(massive.news[0].id);
console.log(massive.news[0].img);
console.log(massive.news[0].title);
console.log(massive.news[0].url);
}
}
xmlhttp.open("GET","http://news.smi2.ru/data/js/81060.js",true);
xmlhttp.send();
Problem
please help bring an array of data. spring is here: ``` {"news": [{"img": "http://static2.smi2.net/img/160x120/2212764.jpeg", "title": "Усиление слуха в 2 - 3 раза! Уникальная разработка", "url": "http://news.smi2.ru/newdata/news?ad=681120&bl=81060&ct=adpreview&st=16&in=lJUrBQDHL4CgZAoA", "id": "681120"}]} ``` I do the following: ``` var massive = JSON.parse('http://news.smi2.ru/data/js/81060.js'); console.log(massive.news.id); console.log(massive.news.img); console.log(massive.news.title); console.log(massive.news.url); ``` The result is the following error message: Uncaught SyntaxError: Unexpected token h use only the native js