【问题标题】:Best practices for calling intuit.ipp.anywhere.setup()?调用 intuit.ipp.anywhere.setup() 的最佳实践?
【发布时间】:2014-02-19 18:10:30
【问题描述】:

这是一个关于进行生成标准“连接到 QuickBooks”按钮(用于通过 Intuit 的 v3 REST API 建立到 QuickBooks Harmony 的连接)的 JavaScript 调用的最佳实践的问题。

如果我按照 Intuit 的例子,我会:

  1. 在脚本标签中引用https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere.js
  2. 标签集放在我希望“连接到 QuickBooks”按钮显示的位置
  3. 祈祷 intuit.ipp.anywhere.js 不会重定向到停机消息,再次仍然存在
  4. 打电话给 intuit.ipp.anywhere.setup()
  5. 查看“连接到 QuickBooks”按钮

...有效(对于“有效”的许多值),但感觉很脆弱:

  1. 如果 intuit.ipp.anywhere.js 正在重定向到停机消息(阅读:不是 JavaScript)或不可用,我将收到脚本错误。
  2. 如果我收到脚本错误(或 Intuit 的脚本副本出现其他问题),则不会向用户提供任何反馈,只有“连接到 QuickBooks”按钮应位于的空白区域。李>

为了让这一切更有弹性,我将对 intuit.ipp.anywhere.js 的引用和对 intuit.ipp.anywhere.setup() 的调用组合到一个 JQuery .ajax() 调用中:

    $.ajax({
     url: 'https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere.js', 
     type: 'GET',
     dataType: 'script',
     timeout: 4000,
     success: function(response) {
      if (typeof intuit !== 'undefined') {
       intuit.ipp.anywhere.setup({
        menuProxy: 'MYMENUPROXYURL.aspx',
        grantUrl: 'MYGRANTURL.aspx'
       });
      }
     },
     error: function(x, t, m) {
       // show some friendly error message about Intuit downtime
     }        
    });

...这也有效(对于“有效”的更多值):

  1. 我对 setup() 的调用包含在成功处理程序中(以及对 intuit 对象是否存在的额外检查),因此如果出现问题,我不应该收到脚本错误。
  2. 如果 Intuit 脚本的 GET 超时(4000 毫秒后)或返回非脚本内容,我将向用户显示一条友好的错误消息。

还有其他人采取了不同的方法吗? Intuit 又重新上线了吗?

【问题讨论】:

  • 嘿,这看起来是一个很好的开始 - 这是否会让您的浏览器停止使用本地缓存?
  • @TroyAnderson 我们使用.getScript 函数,该函数默认将缓存设置为“假”。通过 The Machete 的帖子,他可以在 .ajax 参数中添加明确的 cache: false
  • @TroyAnderson 在.ajax 参数上不需要显式的cache: false,因为dataType: script 会将缓存值默认为false (reference)

标签: quickbooks intuit-partner-platform quickbooks-online


【解决方案1】:

这与我们的处理方式类似。我们已经将它包装在 jQuery.getScript 调用中,但显然 .fail 处理程序不适用于跨域脚本标签。我们的解决方案如下:

<script type="text/javascript>
    var timeoutID;
    timeoutID = window.setTimeout(function () {
        $("#ippConnectToIntuit").replaceWith('<p class="error-message">There was a problem communicating with QuickBooks. The service may be down or in heavy use. Try again later.</p>');
        }, 5000);
    $.getScript("https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere.js")
        .done(function () {
            window.clearTimeout(timeoutID);
            intuit.ipp.anywhere.setup({
                menuProxy: '/path/to/our/menu/proxy',
                grantUrl: '/path/to/our/grant/url'
            });
        });
</script>
<div id="ippConnectToIntuit"><ipp:connecttointuit></ipp:connecttointuit></div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-17
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 2017-11-12
    • 2019-01-29
    • 2011-11-17
    相关资源
    最近更新 更多