title: Sending data via jQuery Ajax as JSON to PHP Rest API with cURL
body: <p>I need to send some data to a REST API and include a custom header value. I try and echo out the data I am sending via the cURL script, but I get a blank page. 
  Here is my HTML</p>
  
  <pre><code>&lt;form id="RestData" action=Processor.php" method="POST"&gt;
      &lt;ul&gt;
          &lt;li&gt;
              &lt;input type="text" id="email" name="email"&gt;
          &lt;/li&gt;
          &lt;li&gt;
              &lt;input type="submit" value="Update User" id=""&gt;
          &lt;/li&gt;
      &lt;/ul&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>my jQuery:</p>
  
  <pre><code>$(function(){
      $('#RestData').validate({
          errorPlacement: function(error, element) {},
          submitHandler: function(form) {
              $.ajax({
                  type:$('#RestData').attr('method'),
                  url: form.action,
                  data: {
                      email = $('#email').val();
                  },
                  beforeSend: function(data){
                      console.log(data);
                  },
                  success: function(data){
                      console.log(data);
                      if(data.type == "error") {
                          //error handling
                      } else if(data.type == "success"){
                          //success handling
                      } 
                  }
              });
                  return false;
          },
          rules: {
              email: {
                  required:true,
                  email:true
              }
          }
      });
  });
  </code></pre>
  
  <p>At this point, I am getting double quotes around my json array when I echo it out via the PHP processor</p>
  
  <pre><code>&lt;?php
      $email = $_POST['email'];
      $expired = NULL;
      $funded = TRUE;
  
      $data = array(
          "email" =&gt; $email,
          "expired" =&gt; $expired,
          "funded" =&gt; $funded
      );
      echo json_encode($data);
  ?&gt;
  </code></pre>
  
  <p>like this -> {"email":"test@test.com","expired":null,"funded":true}
  I don't know if that will be an issue or not, any thoughts on how to remove if necessary?</p>
  
  <p>With my final cURL code, nothing happens - blank screen and nothing in the network panel for a response.</p>
  
  <pre><code>&lt;?php
      $email = $_POST['email'];
      $expired = NULL;
      $funded = TRUE;
  
      $data = array(
          "email" =&gt; $email,
          "expired" =&gt; $expired,
          "funded" =&gt; $funded
      );
  
      $url = 'https://rest.api';
  
      $json_string = json_encode($data);
  
      $headers = array (
          "Content-Type: application/json; charset=utf-8",
          "Content-Length: " .strlen($json_string),
          "Authorization: Bearer long token here"    
      );
  
      $channel = curl_init($url);
      curl_setopt($channel, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($channel, CURLOPT_CUSTOMREQUEST, "PUT");
      curl_setopt($channel, CURLOPT_HTTPHEADER, $headers);
      curl_setopt($channel, CURLOPT_POSTFIELDS, $json_string);
      curl_setopt($channel, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($channel, CURLOPT_CONNECTTIMEOUT, 10);
  
      curl_exec($channel);
      $statusCode = curl_getInfo($channel, CURLINFO_HTTP_CODE);
      curl_close($channel);    
      return $statusCode;
      echo $json_string;
  ?&gt;
  </code></pre>
  
  <p>This is a little outside of my wheelhouse, I use cURL a lot, just not to a rest API. I know I should be getting a response back and am trying to echo it out on the page for debugging purposes, but I just get a blank page.</p>