我尝试使用ajax
创建一个简单的表单我跟随此处的信息:http://solislab.com/blog/5-tips-for-using-ajax-in-wordpress/#admin-ajax
如果我使用此代码
function myajax_submit() {
// get the submitted parameters
$name = $_POST['name'];
$email = $_POST['email'];
// generate the response
$response = json_encode( array( 'success' => true ) );
// response output
header( "Content-Type: application/json" );
echo $response;
// IMPORTANT: don't forget to "exit"
exit;
}
我得到一个解析错误
Parse error: syntax error, unexpected '=', expecting ')' in /Users/worker/Desktop/MAMP-DocRoot/the_site/src/php/wp-content/themes/hub/functions.php on line 49
第59行是
$response = json_encode( array( 'success' => true ) );
如果我注释掉这一行,我会在控制台中收到500内部服务器错误。
http://sitename.co.uk/hub/wp-content/plugins/Users/worker/php/wp-content/themes/hub//js/compiled/main.min.js?ver=3.9.1
表格有效,但我收到空的警告
如果我在“网络”选项卡中单击并单击“admin-ajax.php”,则其状态代码为200 OK