最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript get content of URL - Stack Overflow

programmeradmin2浏览0评论

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 badges
Add a ment  | 

2 Answers 2

Reset to default 3

You 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();    
}
发布评论

评论列表(0)

  1. 暂无评论