我是新來的wordpress,並試圖創建一個簡單的調用,可以從ajax頁面調用。我知道如何用PHP做到這一點,但我無法用wordpress做到這一點。Ajax調用wordpress插件
<?php
/*
Plugin Name: Jed Plugin
*/
function func_rate()
{
$data = wp_remote_retrieve_body (wp_remote_get("https://www.google.com/finance/converter?a=1&from=USD&to=ZAR"));
$pos = strpos($data,'class=bld>');
echo substr($data,$pos+10,7);
}
add_action('get_value', 'func_rate');
我需要創建一個簡單的Ajax調用這個
$.ajax({
url : "https://www.forexforecasts.co.za/wp-content/plugins/test/test.php",
type : 'post',
data : {
action : 'get_value'
},
success : function(response) {
alert(response)
}
});
您應該閱讀[** codex **](https://codex.wordpress.org/AJAX_in_Plugins),Wordpress在對插件進行ajax請求時有非常具體的要求和方法。 – adeneo