Polymer core-ajax 为什么回调不起作用?

Polymer core-ajax why callback not work?

这是我的代码:

<!DOCTYPE html>
<html>
<head>
    <script src="/client/polymer-0.5.2/bower_components/webcomponentsjs/webcomponents.min.js"></script>

    <link href="/client/polymer-0.5.2/bower_components/polymer/polymer.html" rel="import">
    <link href="/client/polymer-0.5.2/bower_components/core-ajax/core-ajax.html" rel="import">

</head>
<body>

    <core-ajax id="directorInfoAjax" url="/main.ashx?action=directorInfo" handleAs="text" on-core-response="callback">
        <script>
            Polymer(
            {
                callback: function ()
                {
                    var bp = this.response;
                }
            });
        </script>
    </core-ajax>

    <script>
        document.addEventListener('polymer-ready', function()
        {
            document.querySelector("#directorInfoAjax").go();
        });
    </script>
</body>
</html>

怎么了?回调不开火

11111111111111111111111111111111111 222222222222222222222222222222222222 333333333333333333333333333333333333

查看以下教程可能会帮助您解决问题:- http://www.tutorialsavvy.com/2014/07/understanding-polymer-core-ajax-element.html

据我所知,您没有按应有的方式使用 <core-ajax>

这里有一个 <core-ajax> 的工作示例:

<!doctype html>
<html>
<head>
  <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
  <title>seed-element Demo</title>
  <script src="https://www.polymer-project.org/components/webcomponentsjs/webcomponents.js"></script>
  <link rel="import" href="https://www.polymer-project.org/components/polymer/polymer.html">
  <link rel="import" href="https://www.polymer-project.org/components/core-elements/core-elements.html">
  <link rel="import" href="https://www.polymer-project.org/components/paper-elements/paper-elements.html">

</head>

<body>

 <core-ajax id="directorInfoAjax" url="http://echo.jsontest.com/key/value" handleAs="text" on-core-response="{{callback}}"></core-ajax>


  <script>
    document.addEventListener('polymer-ready', function() {
      var ajax = document.querySelector("core-ajax");
      ajax.addEventListener("core-response", function(e) {
          alert("I received a response "+ this.response);
          console.log(this.response);
        }
      );
      ajax.go(); // Call its API methods.
    });
  </script>
</body>
</html>

在您的代码中,组件内部的 Polyymer 声明似乎不起作用,即使起作用,回调函数也需要包装在 {{ }}.

这里有一个笨蛋:http://plnkr.co/edit/rOuNPu99D7ROX4ewbLnK?p=preview

希望对您有所帮助,如果没有帮助,请随时询问更多信息!

[编辑] 我写了一个更简单的例子