0

I have been using the following code to successfully read the contents of an external webpage as a string - I haven't used this program in a month or so but it has suddenly stopped working even though the code has not been changed. I suspect the YQL API has been updated but I couldn't find any documentation that I could understand on this. (I am a beginner at JS). If someone could point me to how to update my code it would be much appreciated!

Code:

function formSubmitted(raceID) {
    if(raceID.length < 4 && raceID > 0){
        savedRaceID = raceID;
        raceUrl = "http://www.bbk-online.net/gpt/lap"+raceID+".htm";
        jQuery.ajax = (function(_ajax){

    var protocol = location.protocol,
        hostname = location.hostname,
        exRegex = RegExp(protocol + '//' + hostname),
        YQL = 'http' + (/^https/.test(protocol)?'s':'') + '://query.yahooapis.com/v1/public/yql?callback=?',
        query = 'select * from html where url="{URL}" and xpath="*"';
        function isExternal(url) {
            return !exRegex.test(url) && /:\/\//.test(url);
        }

        return function(o) {

        var url = o.url;

        if ( /get/i.test(o.type) && !/json/i.test(o.dataType) && isExternal(url) ) {
                // Manipulate options so that JSONP-x request is made to YQL
            o.url = YQL;
            o.dataType = 'json';
            o.data = {
            q: query.replace(
                '{URL}',
                url + (o.data ?
                    (/\?/.test(url) ? '&' : '?') + jQuery.param(o.data)
                    : '')
                ),
                format: 'xml'
            };

            // Since it's a JSONP request
            // complete === success
            if (!o.success && o.complete) {
                o.success = o.complete;
                delete o.complete;
            }

            o.success = (function(_success){
                return function(data) {
                    if (_success) {
                        // Fake XHR callback.
                        _success.call(this, {
                            responseText: data.results[0].replace(/<script[^>]+?\/>|<script(.|\s)*?\/script>/gi, '')


//THE ERROR IS COMING FROM ABOVE - REPLACE IS BEING CALLED ON A NULL OBJECT??
//SUGGESTS NO DATA RETURNED?


                            }, 'success');
                        }

                    };
            })(o.success);

        }

        return _ajax.apply(this, arguments);

    };

})(jQuery.ajax);

        $.ajax({
    url: raceUrl,
    type: 'GET',
    success: function(res) {
        processData(res.responseText);
    }
});
    }
    else{
        alert("Please enter a valid race number...");
    }
}

I have highlighted where the error is coming from - it appears that the function is not returning any data?

Tech
  • 156
  • 1
  • 14
  • Well log `data` to console, and see what it actually contains ... – CBroe Jun 21 '17 at 09:37
  • Sorry should have tried that - It produced: {"query":{"count":"0","created":"2017-06-21T09:48:34Z","lang":"en-US","meta":{"message":"html table is no longer supported. See https://policies.yahoo.com/us/en/yahoo/terms/product-atos/yql/index.htm for YQL Terms of Use"}},"results":[]} - I have been on this page already and it is not of any use as far as I can see – Tech Jun 21 '17 at 09:49
  • Well that should at least answer the question whether anything has changed ... Not sure why they link you to the ToS, sounds like they should rather link to the YQL API documentation, so that you can figure out what other options regarding return formats(?) there are. – CBroe Jun 21 '17 at 09:52
  • @Tech, Please see [this answer](https://stackoverflow.com/a/44464349/4092887) if it helps you, give him a upvote. – Mauricio Arias Olave Jun 28 '17 at 14:44

0 Answers0