0
votes

I am trying to crawl a web page using javascript by making use of api on the click of download button. But I don't receive any responseText in this and same api works using curl.

download.addEventListener('click',function(){

    document.getElementById('check').innerHTML = url;

    var yql = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from html where url="' + url + '"') + '&format=json&callback=?';  
    document.getElementById('check').innerHTML = yql;
    var request = new XMLHttpRequest();


    request.onreadystatechange = function(){
        document.getElementById('check').innerHTML= request.readyState;

        if(request.readyState ===XMLHttpRequest.DONE) {
        document.getElementById('check').innerHTML= request.responseText;
       }
    };

    request.open("GET", yql, true);

    request.send;

},false);
1
Shouldn’t there be request.send()?The Witness

1 Answers

-1
votes

Just remove the callback from the ypl and then this code works fine :

download.addEventListener('click',function(){

    document.getElementById('check').innerHTML = url;


    var yql = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from html where url="' + url + '"') + '&format=jsonp';  
    document.getElementById('check').innerHTML = yql;


    var request = new XMLHttpRequest();
    request.open("GET", yql, true);   
    request.send();  

    request.onreadystatechange = function(){
        document.getElementById('check').innerHTML= request.readyState + request.status;
        if(request.readyState ===4) {
            document.getElementById('check').innerHTML= request.responseText;
        }
    };


},false);