Title: Nonce creates a 403 error
Last modified: November 7, 2019

---

# Nonce creates a 403 error

 *  [montanan](https://wordpress.org/support/users/montanan/)
 * (@montanan)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/nonce-creates-a-403-error/)
 * I created a plugin with this code and it works fine. I am creating a second plugin
   and it is giving me a “the server responded with a status of 403 (Forbidden)”
   Error. I used the code from the WordPress.org Plugin Developer Handbook.
 *     ```
       add_action('wp_enqueue_scripts', 'FMS_enqueue_scripts');
       function FMS_enqueue_scripts() {  // this function initialized scripts
   
           wp_enqueue_script( 'my_javascript_js', plugins_url( '/js/my_javascript.js', __FILE__ ), array('jquery'), '1.0', $in_footer = true);
   
           wp_enqueue_style( 'my_css', plugins_url( '/css/my-css.min.css' , __FILE__ ),$deps = array(), '1.0');
   
           $fmn = wp_create_nonce( '34234356' );
   
           wp_localize_script( 'my_javascript_js', 'my_ajax_obj', array(
              'ajax_url' => admin_url( 'admin-ajax.php' ),
              'nonce'    => $fmn,
           ) );
   
   
       }
   
       add_action( 'wp_ajax_nopriv_msc-find-product', 'MSC_FMS_ajax_handler' );
   
       add_action( 'wp_ajax_msc-find-product', 'MSC_FMS_ajax_handler' );
   
       function MSC_FMS_ajax_handler() { // this function gets the ajax data
   
           check_ajax_referer( '34234356'); // checks for the correct nonce
   
           if(array_key_exists('shed', $_POST) ) {
   
               print_r($_POST);
   
           }
           else {
                echo '#';
           }
   
           wp_die(); // All ajax handlers die when finished
       }
       ```
   
 * Here is the Javascript
 *     ```
       jQuery(document).ready(function () {
   
           jQuery("#storage-form").on("submit", function () {
   
               var shedInfo = 'good';
   
               jQuery.post(my_ajax_obj.ajax_url, { //POST request
   
                   _ajax_nonce: my_ajax_obj.nonce, //nonce
   
                   action: "msc-find-product", //action
   
                   shed: shedInfo //data
   
               }, function (data) { //callback
   
                   console.log(data);
                   //window.location.href = data;
   
                   return false;
   
               });
   
               return false;
           });
   
       }) // end ready
       ```
   
    -  This topic was modified 6 years, 7 months ago by [bcworkz](https://wordpress.org/support/users/bcworkz/).
      Reason: unresolved OP resolved in error

Viewing 1 replies (of 1 total)

 *  Thread Starter [montanan](https://wordpress.org/support/users/montanan/)
 * (@montanan)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/nonce-creates-a-403-error/#post-12104881)
 * It is conflicting with my other nonce.
 * Here is the javascript for Plugin One
    `_fmp_nonce: my_ajax_obj.nonce, //nonce`
   Javascript for Plugin Two `_msp_nonce: my_ajax_obj.nonce, //nonce`
 * They both work fine as long as one plugin is not activated or if I comment out
   the check_ajax_referer() line.
    -  This reply was modified 6 years, 7 months ago by [bcworkz](https://wordpress.org/support/users/bcworkz/).
      Reason: consolidate topics

Viewing 1 replies (of 1 total)

The topic ‘Nonce creates a 403 error’ is closed to new replies.

## Tags

 * [ajax](https://wordpress.org/support/topic-tag/ajax/)
 * [nonce](https://wordpress.org/support/topic-tag/nonce/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 1 participant
 * Last reply from: [montanan](https://wordpress.org/support/users/montanan/)
 * Last activity: [6 years, 7 months ago](https://wordpress.org/support/topic/nonce-creates-a-403-error/#post-12104881)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
