我试着用ajax从插件中的php获取一些信息。但获取对未定义函数的错误调用。Ajax
jQuery.ajax({
type: "POST",
url: "<?php echo plugins_url();?>/tester/inc/test.php",
data: { param: \'st1\' }
}).done(function( msg ) {
alert( "Data Saved: " + msg );
});
警报中出错Data Saved: <br />
<font size=\'1\'><table class=\'xdebug-error xe-fatal-error\' dir=\'ltr\' border=\'1\' cellspacing=\'0\' cellpadding=\'1\'>
<tr><th align=\'left\' bgcolor=\'#f57900\' colspan="5"><span style=\'background-color: #cc0000; color: #fce94f; font-size: x-large;\'>( ! )</span> Fatal error: Call to undefined function add_action() in E:\\wamp1\\wamp\\www\\wp_twentythirteen\\wp-content\\plugins\\tester\\inc\\test.php on line <i>7</i></th></tr>
<tr><th align=\'left\' bgcolor=\'#e9b96e\' colspan=\'5\'>Call Stack</th></tr>
<tr><th align=\'center\' bgcolor=\'#eeeeec\'>#</th><th align=\'left\' bgcolor=\'#eeeeec\'>Time</th><th align=\'left\' bgcolor=\'#eeeeec\'>Memory</th><th align=\'left\' bgcolor=\'#eeeeec\'>Function</th><th align=\'left\' bgcolor=\'#eeeeec\'>Location</th></tr>
<tr><td bgcolor=\'#eeeeec\' align=\'center\'>1</td><td bgcolor=\'#eeeeec\' align=\'center\'>0.0007</td><td bgcolor=\'#eeeeec\' align=\'right\'>254944</td><td bgcolor=\'#eeeeec\'>{main}( )</td><td title=\'E:\\wamp1\\wamp\\www\\wp_twentythirteen\\wp-content\\plugins\\tester\\inc\\test.php\' bgcolor=\'#eeeeec\'>..\\test.php<b>:</b>0</td></tr>
</table></font>
测试。php<?php
function aj()
{
echo "hello";
echo plugins_url();
}
add_action(\'wp_ajax_my_action\',\'aj\');
add_action(\'wp_ajax_nopriv_myFunction\',\'aj\');
?>
我认为错误表示好像我不在wordpress内。有什么想法吗?