run admin-ajax.php returning 400

52 views Asked by At

I have looked over a few other related questions but I must be missing something.

I dont know much PHP but I am hoping someone can help tell me where iv gone wrong. The site is saying that /wp-admin/admin-ajax.php comes back as a 400 error

  • Status400 Bad Request
  • VersionHTTP/1.1
  • Transferred616 B (1 B size)
  • Referrer Policystrict-origin-when-cross-origin

Code below - 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( '[email protected]', $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' );
0

There are 0 answers