If I enter this link, I get an array of search suggestions for the word 'sun' in a textfile 'f.txt'
;q=sun
How can I get this into an array in Javascript using only this URL?
If I enter this link, I get an array of search suggestions for the word 'sun' in a textfile 'f.txt'
http://suggestqueries.google./plete/search?client=firefox&q=sun
How can I get this into an array in Javascript using only this URL?
Share Improve this question asked Oct 5, 2014 at 12:00 enzianenzian 1,7313 gold badges18 silver badges20 bronze badges2 Answers
Reset to default 3You can make a request using AJAX and then parse the result into a JavaScript object using JSON.parse
:
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState === 4) {
var response = req.responseText;
var json = JSON.parse(response);
console.log(json)
}
};
req.open('GET', 'http://suggestqueries.google./plete/search?client=firefox&q=sun');
req.send(null);
function httpGet(theUrl)
{
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
return xmlhttp.responseText;
}
}
xmlhttp.open("GET", theUrl, false );
xmlhttp.send();
}