문제

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