title: Why is the Ajax response adding the post details WP
body: <p>For some reason the below Ajax response is adding the post details, and that is not the intended application.</p>
  
  <p>I want to use only the post id that returns in the end.
  Furthermore I tried to figure out why is my Ajax returning the details in text type and not in JSON type as I wished for?.</p>
  
  <p><a href="https://i.stack.imgur.com/qRYPj.png" rel="nofollow noreferrer">This is the outcome of the response</a></p>
  
  <p>Here is my JS code:</p>
  
  <pre><code>createRate(){
      var ourNewPost = {
          'title': $(".new-rate-title").val(),
          'content': $('.new-rate-body').val(),
          'rate': $('.custom-star:checked').val(),
          'productId': $('.submit-rate').data('id')
      }
  
      $.ajax({
          // adding nonce key to make wordpress know we are looged in and has the permision to do that method.
          beforeSend: (xhr) =&gt; {
              xhr.setRequestHeader('X-WP-Nonce', ylsData.nonce);
          },
          url: ylsData.root_url + '/wp-json/yls/v1/rating/',
          type: 'POST',
          data: ourNewPost,
          dataType:"text",
          success: (response) =&gt; {
  
              console.log('congrats');
              console.log(response);
          },
          error: (response) =&gt; {
              console.log('failed');
              console.log(response);
  
          }
      }); 
  }
  </code></pre>
  
  <p>and here is my php route code:</p>
  
  <pre><code>add_action('rest_api_init','ylsRateRoute');
  
  
  function ylsRateRoute(){
      register_rest_route('yls/v1','rating',array(
          'methods' =&gt; 'POST',
          'callback'=&gt; 'createLike'
      ));
  
  }
  
  function createLike($data){
      if(is_user_logged_in()){
          $title = sanitize_text_field($data['title']);
          $content = sanitize_text_field($data['content']);
          $rateNum = sanitize_text_field($data['rate']);
          $productId = sanitize_text_field($data['productId']);
          if(get_post_type($productId) == 'product'){
              return wp_insert_post(array(
                  'post_title' =&gt; $title,
                  'post_type' =&gt; 'rate',
                  'post_content' =&gt; $content,
                  'post_status' =&gt; 'publish',
                  'meta_input' =&gt; array(
                      'rate_related_product' =&gt; $productId,
                      'rating_rate' =&gt; $rateNum
                  )
                ));
          }else{
              die("Invalid product id");
          }
        }else{
          die("you must be logged in first");
        }
  }
  </code></pre>