Question

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) );
        });
    }); 
});
Était-ce utile?

La solution

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 );
        });
    }); 
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top