Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make copy works inside an ajax callback #66

Closed
picov opened this issue Oct 28, 2017 · 1 comment
Closed

How to make copy works inside an ajax callback #66

picov opened this issue Oct 28, 2017 · 1 comment

Comments

@picov
Copy link

picov commented Oct 28, 2017

Hi,
i need to copy the text returned from an AJAX request that fire when a button is clicked.
The problem is that inside the click event listener I call the function that perform the AJAX request but the returned data are processed inside a callback function (ajax success) that is no more inside the original click event listener, thus the copy fails.
The only walk around that make copy works is to make the ajax call synchronous (async: false jQuery option).
I'm wondering if there is another way to make copy works in my scenario that keep AJAX async (as it should be).
Thank you.

@lgarron
Copy link
Owner

lgarron commented Oct 31, 2017

I'm wondering if there is another way to make copy works in my scenario that keep AJAX async (as it should be).

At the moment, there is not. Browsers require specifying the data to be copied synchronously at copy time (and the copy action must be triggered in direct response to a user gesture). If you absolutely cannot have your data ready synchronously, I suggest having a button to generate the data, which then reveals an actual copy button when the data is ready.

See w3c/clipboard-apis#41 for possible better approaches in the future.

@lgarron lgarron closed this as completed Oct 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants