gpt4 book ai didi

javascript - 使用 YQL 查询进行 HTML 和 JS 调试

转载 作者:行者123 更新时间:2023-11-28 04:30:08 25 4
gpt4 key购买 nike

谁能帮我调试这个吗?它应该用当前筹款金额的值更新温度计。在不再支持 YQL html 表之前它就可以工作。我根据此处找到的答案更新了 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);

关于javascript - 使用 YQL 查询进行 HTML 和 JS 调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44685701/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com