Last active
October 12, 2018 09:11
-
-
Save RiodeJaneiroo/fbbf6bab13eedc0bfa6a064b1fc7b203 to your computer and use it in GitHub Desktop.
[AJAX Request – Wordpress] Ajax request wordpress #ajax #wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'wp_ajax_misha', 'test_function' ); // wp_ajax_{ЗНАЧЕНИЕ ПАРАМЕТРА ACTION!!} | |
add_action( 'wp_ajax_nopriv_misha', 'test_function' ); // wp_ajax_nopriv_{ЗНАЧЕНИЕ ACTION!!} | |
// первый хук для авторизованных, второй для не авторизованных пользователей | |
function test_function(){ | |
$summa = $_POST['param1'] + $_POST['param2']; | |
echo $summa; | |
die; // даём понять, что обработчик закончил выполнение | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#misha_button').click(function(){ | |
$.ajax({ | |
url: '<?php echo admin_url("admin-ajax.php") ?>', | |
type: 'POST', | |
data: 'action=misha¶m1=2¶m2=3', // можно также передать в виде массива или объекта | |
beforeSend: fucntion( xhr ) { | |
$('#misha_button').text('Загрузка, 5 сек...'); | |
}, | |
success: function( data ) { | |
$('#misha_button').text('Отправить'); | |
alert( data ); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment