HTML 和使用 YQL 查询的 JS 调试

HTML and JS debugging with YQL query

谁能帮我调试一下?它应该用当前筹款金额的值更新温度计。它在 YQL html table 不再受支持之前工作。我根据在这里找到的答案更新了 REST 查询,现在可以看到数据,但它没有更新温度计。任何建议表示赞赏!

<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>

这是对您的脚本的更改,但有一些技巧 JavaScript,它正在运行。

工作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);