سؤال

So i have the below function with nested function. My problem is that the $this statement inside the success function is not being called. It should be calling the value of the input field via alter the value of the specified input field. Not sure what i have wrong in my code. Everyhting is working fine (php processing, etc) but the success function that alerts $this.val() is not working. Any help would be appreciated.

$('input.File').each(function() {   
    $(this).upload(
        'filephp.php', 
        function(success){
            // I want to use $(this), it it doesnt work
           console.log( $(this) );
        });
    }); 
});
هل كانت مفيدة؟

المحلول

Try to store your $(this) inside another variable in order to access it from the success callback:

$('input.File').each(function() {
    $this = $(this); // Save the reference so we can use it in the ajaxcall
    $(this).upload(
        'filephp.php', 
        function(success){
           // You can now use $this (no brackets)
           console.log( $this );
        });
    }); 
});
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top