【问题标题】:Meteor script loading with data attributes使用数据属性加载 Meteor 脚本
【发布时间】:2015-06-25 01:22:07
【问题描述】:

我有这个

<script 
src="https://cdn.plaid.com/connect/stable/connect-initialize.js" 
data-client-name="Client Name" 
data-form-id="plaidForm" 
data-key="public_key" 
data-product="auth" 
data-env="tartan" 
data-webhook="/webhook" 
/>

如何在一个 Meteor 模板中将其转换为可工作的跨浏览器脚本?

我通过在 template.js 渲染函数中像这样加载它来让它在 Chrome 中工作,但是当我使用 Ionic 时它不能正确加载到移动设备上。我不知道为什么,但我试图先找到最简单的答案(也许 Ionic 无法识别我的 javascript 代码)...

感谢任何帮助。

$(document).ready(function() {
        var script = document.createElement('script');
        script.async = "async";
        script.src = "https://cdn.plaid.com/connect/stable/connect-initialize.js";
        script.setAttribute("data-client-name", "Client Name");
        script.setAttribute("data-form-id", "plaidForm");
        script.setAttribute("data-key", Meteor.settings.public.plaid.public_key);
        script.setAttribute("data-product", "auth");
        script.setAttribute("data-env", "tartan");
        script.setAttribute("data-webhook", "https://e39f6d752a20d470.a.passageway.io/hookthe/plaid");
        $("head").append(script);
    });

这是我在 Android 模拟器上运行的浏览器检查的结果。

Failed to load resource: the server responded with a status of 404 (Not Found)
https://cdn.plaid.com/connect/stable/connect-initialize.js?_=1429320699573

【问题讨论】:

  • 你解决过这个问题吗?
  • 没有。 Plaid 计划在接下来的几周内发布几个更新,包括设置脚本的更好方法。在等待其中一些时,我已将其放在一边。

标签: cordova meteor ionic meteoric


【解决方案1】:

我意识到这个答案有点晚了,但是 Link 使用 Meteor 应该没有问题。 404 也很奇怪,因为我可以直接在浏览器中访问该 URL。

你能解决这个问题吗?如果您仍然对 Meteor 有疑问,我建议您尝试 Link 的 custom initializers,它不依赖于“data-”属性。

【讨论】:

    【解决方案2】:

    奇怪的是,Link 在您的浏览器中运行,但在您的 Ionic 应用程序中却没有。上周我使用 Link 构建了一个 Ionic 应用程序,它可以正常运行,所以我认为您这边出了点问题。

    在您的 Ionic 应用程序中:您使用的是 AngularJS + UIrouter 吗?我认为可能发生的事情是您正在将链接 &lt;script&gt; 标记加载到 ng-template 脚本标记内 - 这不起作用(脚本中的脚本永远不会执行)。我可能会建议您在 Angular 控制器中尝试使用 custom initializer 来避免这个问题。

    plaidApp.controller('BillsCtrl', function($scope, $http) {
    
     var linkHandler = Plaid.create({
       env: 'tartan',
       clientName: 'Client Name',
       key: 'test_key',
       product: 'auth',
       onSuccess: handleOnSuccess,
     });
    
     function handleOnSuccess(token) {
       $http.post('/authenticate/', {
         public_token: token
       }).success(function(res) {
       }).error(function(err) {
       })
     }
    
    });
    

    在您的 index.html 文件中的某处包含 Plaid 脚本标签

    <script src="https://cdn.plaid.com/link/stable/link-initialize.js"></script>
    

    如果这不起作用,您可以create a new issue in our github page,以便我们更好地回应您的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-14
      • 1970-01-01
      • 2014-04-19
      • 1970-01-01
      相关资源
      最近更新 更多