如何显示我的 YQL/xpath/javascript?

发布于 2024-11-18 13:29:56 字数 1211 浏览 4 评论 0原文

作为练习,我尝试使用 YQL/xpath/javascript 在远程页面上显示塔罗牌图片、卡片名称和含义。我已经像雅虎上的示例一样设置了脚本,但无法让它在浏览器中显示。关于如何改进它以使其显示有什么建议吗?

<html>
  <head>
    <title>Example</title>
      <script type='text/javascript'>
         function tarot(o){
         var div = o.query.results.div;
         var output = '';
     var title = div[0].strong;
     var content = div[0].p.content;
     var src = div[1].img.src;
     output = "<h3>" + title + "</h3></br><p>" + content + "</p><img src='" + src + "' alt="" />";
    document.getElementById('results').innerHTML = output;
  }
     </script>
  </head>
  <body>
    <div id='results'></div>
      <script src="http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fwww.tarot.com%2Fdaily%22%20and%20xpath%3D%22%2F%2Fdiv%5B%40id%3D'cardHolder'%5D%20%7C%20%2F%2Fdiv%5B%40id%3D'cardMeaning'%5D%22&format=json&diagnostics=true&callback=tarot"></script>
  </body>
</html>

非常感谢任何帮助! 〜拉里斯

P.S. - 我更新了代码的 callback=functionName 部分以反映最新的代码。不幸的是,这似乎并不能解决问题。我似乎还缺少其他东西吗?

As an exercise, I'm trying to display a tarot card picture, the name of the card, and the meaning on a remote page using YQL/xpath/javascript. I've set up the script like the example on Yahoo but can't get it to display in the browser. Any suggestions as to how to improve it so it will display?

<html>
  <head>
    <title>Example</title>
      <script type='text/javascript'>
         function tarot(o){
         var div = o.query.results.div;
         var output = '';
     var title = div[0].strong;
     var content = div[0].p.content;
     var src = div[1].img.src;
     output = "<h3>" + title + "</h3></br><p>" + content + "</p><img src='" + src + "' alt="" />";
    document.getElementById('results').innerHTML = output;
  }
     </script>
  </head>
  <body>
    <div id='results'></div>
      <script src="http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fwww.tarot.com%2Fdaily%22%20and%20xpath%3D%22%2F%2Fdiv%5B%40id%3D'cardHolder'%5D%20%7C%20%2F%2Fdiv%5B%40id%3D'cardMeaning'%5D%22&format=json&diagnostics=true&callback=tarot"></script>
  </body>
</html>

Any help is greatly appreciated!
~Larys

P.S. - I updated the callback=functionName part of the code to reflect the most current code. Unfortunately, this doesn't seem to fix the problem. Is there something else I seem to be missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不寐倦长更 2024-11-25 13:29:56

您有callback=cbfunc,但尚未定义function cbfunc

You have callback=cbfunc but you haven't defined function cbfunc

孤者何惧 2024-11-25 13:29:56

我发现的问题是您从未调用 tarot() 函数。

我认为你应该将你的 url 结尾更改为 callback=tarot

希望这会有所帮助。干杯

The problem I see is that you're never calling your tarot() function.

I think you should change your url end to callback=tarot

Hope this helps. Cheers

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文