1 回答

TA貢獻1752條經(jīng)驗 獲得超4個贊
在 Wordpress 中,您應(yīng)該使用內(nèi)置的Ajax 機制。
$.ajax({
? ? type? : "POST",
? ? url: "https://your-site.com/wp-admin/admin-ajax.php",
? ? data: {
? ? ? ? action: 'retrieve_yearvalue',?
? ? ? ? yearValue: $($post).attr("value"),
? ? ? ? test: 'Test is ok'
? ? },
? ? success: function (data) {
? ? ? ? console.log(data);
? ? }
})
在 PHP 端:
add_action( 'wp_ajax_retrieve_yearvalue', 'my_year_retrieve_function' );
add_action( 'wp_ajax_nopriv_retrieve_yearvalue', 'my_year_retrieve_function' );
function my_year_retrieve_function() {
? ? $yearValue = $_REQUEST['yearValue'];
? ? $test = $_REQUEST['test'];
? ??
? ? $response = array(
? ? ? ? 'recieved_year' => $yearValue,
? ? ? ? 'test_data' => $test
? ? );
? ??
? ? wp_send_json( $response );
}
- 1 回答
- 0 關(guān)注
- 117 瀏覽
添加回答
舉報