jquery - zclip and ajax?
I'm using a jquery plugin named zclip, which copies a string to the clipbvoard using a swf file.
I got zclip to work with my website, but I need the string to come from another page using ajax
Here's zclip code:
jQuery('.copyme').zclip({
path:swf_path,
copy:"text to copy goes here"
});
The above works, however it doesn't work when I place it in an ajax call as shown below.
jQuery('.copyme').click(function () {
jQuery.ajax({
type: "POST",
url: testUrl,
data: "test",
success: function(data){
jQuery('.copyme').zclip({
path:swf_path,
copy:data
});
}
});
});
I believe it doesn't work because zclip is triggered on a mousevent, and when you put it inside an ajax call, there's no event. 开发者_运维问答The event happened way before. How can I get this to work?
You can fetch the data before the actual click happens, such as on document.ready
.
$(function() {
$.post(testUrl, {
data: 'test' // data posted must be key-value pairs, btw
}, function(data) {
$('.copyme').zclip({
path: swf_path,
copy: data
});
});
});
Demo: http://jsfiddle.net/mattball/TREmT/
精彩评论