- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试 add the PayPal Smart Payment button to my website .用于呈现按钮的 HTML 容器通过 AJAX 请求接收,其中 paypal.Buttons.render()
方法称为 AJAX 请求的 onsuccess
。现在一切正常,除了按钮需要一些时间在网站上呈现并激活。我想提示我的用户按钮正在呈现或加载,因此当 AJAX 请求返回并且没有显示按钮时,他们不会蒙在鼓里。有没有办法知道按钮何时完全呈现?
$.ajax({
url: example/foler,
data: data,
success: success(data)
});
function success(data) {
// data = <div id='paypal-button-container'></div>
paypal.Buttons().render('#paypal-button-container');
// Display "Button Loading..."
// Find out if button has completely rendered, then turn off "button loading..."
}
最佳答案
您可以使用 .then(callback),因为 render() 返回一个 Promise。
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises
A Promise is an object representing the eventual completion or failure of an asynchronous operation. Since most people are consumers of already-created promises, this guide will explain consumption of returned promises before explaining how to create them.
Essentially, a promise is a returned object to which you attach callbacks, instead of passing callbacks into a function.
$.ajax({
url: example/foler,
data: data,
success: success(data)
});
function success(data) {
// data = <div id='paypal-button-container'></div>
// Display "Button Loading..."
paypal.Buttons().render('#paypal-button-container').then(function() {
// Button has completely rendered, then turn off "button loading..."
});
}
关于javascript - 如何知道 PayPal Smart Payment Button 是否完成渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59284271/
我遇到过这个 html: 上面的html和这个有什么区别: 最佳答案 来自MDN page on the tag : 对于 type 的属性标签,可能的值是: 提交:按钮将表单数据提交给服务器
Button button= (Button) findViewbyID(R.id.button); 和 Button button = new Button(this); 有什么区别? 最佳答案 有
我是一名优秀的程序员,十分优秀!