我已经查看了其他一些相关问题,但我一定遗漏了一些东西。
我不太了解 PHP,但我希望有人可以帮助告诉我 iv 哪里出错了。该网站说这/wp-admin/admin-ajax.php
是一个 400 错误
- Status400 错误请求
- 版本HTTP/1.1
- Transferred616 B(1 B尺寸)
- Referrer Policystrict-origin-when-cross-origin
下面的代码 - functions.php
function ajax_submit_abuseform() {
header( 'Content-type: application/json' );
// Handle request then generate response using WP_Ajax_Response
$data = $_POST['data'];
$postid = $data['postid'];
$message = 'Post Link: ' . get_post_permalink($postid)
. '<br />Reported File: ' . $data['reportedfilepath']
. '<br />Abuse Description: ' . $data['inputabusedetails'];
$headers = ""; $attachments = "";
$subject = wp_get_current_user()->user_login . ' reported site abuse: PostID ' . $data['postid'];
add_filter( 'wp_mail_content_type', 'set_html_content_type' );
wp_mail( 'SAMPLE@EMAIL.COM', $subject, $message, $headers, $attachments );
remove_filter( 'wp_mail_content_type', 'set_html_content_type' );`
$response = array(
'message'=>$message,
'filereported'=>$data['reportedfilepath'],
'postid'=>$data['postid'],
'data'=>'<p><strong>Hello world!</strong></p>'
);
$xmlResponse = new WP_Ajax_Response($response);
$xmlResponse->send();
exit();
}
function setupcustomajaxscript() {
$localize = array(
'ajaxurl' => '/wp-admin/admin-ajax.php'
);
wp_enqueue_script( 'submit_abuseform', '/devteamfiles/inc/lightboxreportlink.js', 'jquery', true, '1.6');
wp_localize_script( 'submit_abuseform', 'my_ajax_script', $localize);
}
add_action( 'wp_enqueue_scripts', 'setupcustomajaxscript' );
add_action( 'wp_ajax_submit_abuseform', 'ajax_submit_abuseform' );
add_action( 'wp_ajax_nopriv_submit_abuseform', 'ajax_submit_abuseform' );