简体   繁体   中英

HTML and JS debugging with YQL query

Can anyone help me debug this? It's supposed to update the thermometer with the value of the current fundraising amount. It was working prior to the YQL html table no longer being supported. I updated the REST query based on an answer I found here and now see the data, but it's not updating the thermometer. Any advice is appreciated!

<div style="text-align:center;"><a href="http://www.coolfundraisingideas.net/" alt="Fundraising Thermometer"><img id="thermometer" border="0" src="http://www.coolfundraisingideas.net/thermometer/thermometer.php?currency=dollar&goal=100&current=25&color=red&size=large"></a>
    <p style="font-size:.8em; color:#999">Provided by <a href="http://www.coolfundraisingideas.net/" rel="nofollow" style="display:block; text-decoration:none; font-size:.8em; color:#999">CoolFundraisingIdeas.net</a></p>
</div>
<script>
    function therData() {
        var current = arguments[0].query.results.body.root.eventfundraisingtotals_collection.eventfundraisingtotals.eventverifiedtotalcollected;
        var goal = arguments[0].query.results.body.root.eventfundraisingtotals_collection.eventfundraisingtotals.eventverifiedfundraisinggoal;
        document.getElementById('thermometer').src = 'http://www.coolfundraisingideas.net/thermometer/thermometer.php?currency=dollar&goal=' + goal + '&current=' + current + '&color=red&size=large';
        document.getElementsByTagName('head')[0].removeChild(document.getElementById('therScript'));
    }
    var therScript = document.createElement('script');
    therScript.setAttribute('id', 'therScript');
    therScript.src =
        "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20htmlstring%20where%20url%3D'http%3A%2F%2Fmy.e2rm.com%2Fwebgetservice%2Fget.asmx%2FgetEventFundraisingTotals%3FeventID%3D223256%26loginOrgID%3DASOSEW%26locationExportID%3D%26Source%3D'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=therData";
    document.getElementsByTagName('head')[0].appendChild(therScript);
</script>

This is a change to your script, but with some crafty JavaScript, it's working.

Working fiddle: https://jsfiddle.net/kay6jpqx/

HTML:

<div style="text-align:center;">
  <a href="https://www.coolfundraisingideas.net/" alt="Fundraising Thermometer">
  <img id="thermometer" border="0" src="https://www.coolfundraisingideas.net/thermometer/thermometer.php?currency=dollar&goal=100&current=50&color=red&size=large"></a>
  <p style="font-size:.8em; color:#999">Provided by <a href="https://www.coolfundraisingideas.net/" rel="nofollow" style="display:block; text-decoration:none; font-size:.8em; color:#999">CoolFundraisingIdeas.net</a>
  </p>
</div>

JavaScript:

function therData(arguments){
  //console.log(arguments.query.results.result);
  var res = arguments.query.results.result;

  //get the current amount from the result
  var startPos = res.indexOf("eventverifiedtotalcollected")+28;
  var endPos = res.indexOf("/eventverifiedtotalcollected")-1;
  var evtVerTotal = res.substring(startPos, endPos);
  console.log(evtVerTotal);

  //get the goal amount from the result
  startPos = res.indexOf("eventverifiedfundraisinggoal")+29;
  endPos = res.indexOf("/eventverifiedfundraisinggoal")-1;
  var evtVerGoal = res.substring(startPos, endPos);
  console.log(evtVerGoal);

  var current = evtVerTotal;
  var goal = evtVerGoal
  document.getElementById('thermometer').src = 'http://www.coolfundraisingideas.net/thermometer/thermometer.php?currency=dollar&goal=' + goal + '&current=' + current + '&color=red&size=large';
}

var therScript = document.createElement('script');
therScript.setAttribute('id', 'therScript');
therScript.src = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20htmlstring%20where%20url%3D'http%3A%2F%2Fmy.e2rm.com%2Fwebgetservice%2Fget.asmx%2FgetEventFundraisingTotals%3FeventID%3D223256%26loginOrgID%3DASOSEW%26locationExportID%3D%26Source%3D'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=therData";
document.getElementsByTagName('head')[0].appendChild(therScript);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM