It seems that i cannot access $(this) inside jquery ajax success function. please see below code.
$.ajax({ type: 'post', url: '<?php echo site_url('user/accept_deny_friendship_request')?>', data: 'action='+$action+'&user_id='+$user_id, success: function(response){ //cannot access $(this) here $(this).parent().remove(); } });
You can store your promise, you can pass it around, you can use it as an argument in function calls and you can return it from functions, but when you finally want to use your data that is returned by the AJAX call, you have to do it like this: promise. success(function (data) { alert(data); });
Description. The ajaxSuccess( callback ) method attaches a function to be executed whenever an AJAX request completes successfully. This is an Ajax Event.
Check out the context option - works perfectly for me:
$.ajax({ context: this, type: 'post', url: '<?php echo site_url('user/accept_deny_friendship_request')?>', data: 'action='+$action+'&user_id='+$user_id, success: function(response){ //can access this now! } });
What should $(this)
be? If you have a reference to it outside that function, you can just store it into a variable.
$('#someLink').click(function() { var $t = $(this); $.ajax( ... , function() { $t.parent().remove(); }); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With