I need to copy value of data in ajax success function
$.ajax({
url: 'images/getDownloadUrl/',
dataType: 'text',
async: false,
processData: false,
contentType: false,
type: 'POST',
success: function(data){
document.execCommand(data);
}
});
How can i copy value of this variable data to clipboard, because this is not work if i only put execCommand?
I need to copy value of data in ajax success function
$.ajax({
url: 'images/getDownloadUrl/',
dataType: 'text',
async: false,
processData: false,
contentType: false,
type: 'POST',
success: function(data){
document.execCommand(data);
}
});
How can i copy value of this variable data to clipboard, because this is not work if i only put execCommand?
Share Improve this question asked May 31, 2017 at 14:36 alonso05alonso05 1351 gold badge4 silver badges15 bronze badges 4- 1 Possible duplicate of How do I copy to the clipboard in JavaScript? – Bernd Strehl Commented May 31, 2017 at 14:40
-
How is this ajax call triggered? The browser must be able to attribute the
execCommand
to a user trusted event such as "onClick" – bm_i Commented May 31, 2017 at 14:51 - i found this, but it's not the same problem, because i have problem with ajax – alonso05 Commented May 31, 2017 at 14:52
- @bm_i it is triggered with event onClick function that contain this ajax – alonso05 Commented May 31, 2017 at 14:53
2 Answers
Reset to default 6You can copy your data to clipboard like that :
$.ajax({
url: 'images/getDownloadUrl/',
dataType: 'text',
async: false,
processData: false,
contentType: false,
type: 'POST',
success: function(data){
let copyFrom = document.createElement("textarea");
document.body.appendChild(copyFrom);
copyFrom.textContent = data;
copyFrom.select();
document.execCommand("copy");
copyFrom.remove();
}
});
With async: false
, it works for me, but only once. The copy works one time, for the first click on the button which does the ajax call. Using multiple buttons also does not work - only the first click on any one button works.
Copy never works with async: true
.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744374643a4571123.html
评论列表(0条)