开发者

Ajax upload with jquery selector callback problem

Ok folks,

basically I need to change the value of the input (which is the upload button in this case) clicked on after the upload begins and finishes etc, which you can see in my code. The problem is there could be a number of these fields ( makes sense in the context of what its for ) created on the page, so I have to use $(this) so only the element clicked (#up for instance) get the call back changes. I cant seem to figure this out at all.

Would greatly appreciate the help.

Im using this plugin, http://valums.com/ajax-upload/, to do this and heres my code :

new AjaxUpload('#up', {
    name:'uploadedfile', 
    action: 'image-upload.php', 
    onSubmit: function(file, extension) {
        $(this).val("uploading...");    
    },

    onComplete: function(fi开发者_开发技巧le, response){

        $(this).val(response).removeClass('unactive');

        }


    });

Thanks!


A work around:

var up = $("#up");
new AjaxUpload(up, {
   ...
   onSubmit: function(file, ext) {
       up.val("uploading...");
   }, 
   ...
});

Using how scoping and closures work you can just look up the chain for up. This also caches your selector.

This kind of thing is common practice with that = this or self = this

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜