title: Ajax not posting data to PHP in JSON object
body: <p>i have tried multiple ways using different ajax methods and cant get this to work. I am new to ajax and json so i thought this may be cause the data is not in a form but i have other ajax process's structured the same and they work. the inputs are picked up on click and appears in console but it seems the data: isnt sending the variables to php because when it fails the data returns undefined in alert box. the sql query etc runs fine in php myadmin so im at the end and lost haha! hoping someone can help me!! thanks in advanced!</p>
  
  <p>HTML</p>
  
  <pre><code>&lt;?php 
      $page = "Blog | Fakebook"; 
      include "../inc/connect.php"; 
      include "../inc/login-check.php"; 
      include "../inc/header.php";
      include "../inc/menus.php";
  
  
  ?&gt;
  &lt;div id="content-wrap" class="create-a-blog"&gt;
      &lt;?php
          include "../inc/modals.php"; 
          echo "&lt;input type='hidden' name='author' value='" . $_SESSION['userID'] . "' /&gt;"
      ?&gt;
      &lt;div id="hero"&gt;
          &lt;a id="ajax-blog-bg" class="btn btn-hollow-wht add-img"&gt;Add Image&lt;/a&gt;
          &lt;a id="ajax-publish-blog" class="btn btn-hollow-wht pub-blg"&gt;Publish Blog&lt;/a&gt;
          &lt;section class='create-blog-title'&gt;
              &lt;textarea id="edit-blog-title" name="blog-title" class="title-input" &gt;Enter Blog Title&lt;/textarea&gt;
  &lt;!--            &lt;p&gt;Date and your name will be shown here&lt;/p&gt;--&gt;
          &lt;/section&gt;
      &lt;/div&gt;  
      &lt;div id="create-blog-content"&gt;
          &lt;div class="container rel"&gt;
              &lt;article class="article"&gt;
                  &lt;textarea id="edit-blog-content" rows='4' name='blog-content' cols='50' &gt;Go ahead and get your blog started&lt;/textarea&gt;
              &lt;/article&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>AJAX</p>
  
  <pre><code>$("#ajax-publish-blog").click(function (e){
          event.preventDefault();
          var blogTitle = $('#edit-blog-title').val();
          var content = $('#edit-blog-content').val();
          var image = $('.create-a-blog #hero').css('background-image');
          var cleanup = /\"|\'|\)/g;
          var bg = image.split('/').pop().replace(cleanup, '');
          var authorID = $('input[name=author]').val();
          console.log("Blog Title = " + blogTitle + " // Blog Content = " + content + " // bg image = " + bg + " // authorID =" + authorID);
  
          $.ajax({
              url: "../process/post-blog-process2.php",
              type: "POST",
              data: { blogTitle: blogTitle, content: content, image: bg, authorID: authorID },
              dataType: 'json',
              success: function(data){
                  alert("ohyer" + " " + data.title + " " + data.authorID + " " + data.content + " " + data.image) 
              },
              error: function(data) {
                  alert("ohno" + " " + data.title + " " + data.authorID + " " + data.content + " " + data.image)
              }
          });
      });
  </code></pre>
  
  <p>PHP</p>
  
  <pre><code>&lt;?php
      session_start(); //start a session  
      include "../inc/connect.php"; //include the database connection 
  
      //prevent SQL injection and get data from inputs
      $blogTitle = mysqli_real_escape_string($con, $_POST['blogTitle']);
      $image = mysqli_real_escape_string($con, $_POST['image']); 
      $content = mysqli_real_escape_string($con, $_POST['content']); 
      $authorID = mysqli_real_escape_string($con, $_POST['author']);
  
  
      $sql="INSERT INTO blog (blogTitle, image, content, date, authorID) VALUES ('$blogTitle', '$image', '$content', NOW(), '$authorID')";
      $result = mysqli_query($con, $sql) or die(mysqli_error($con)); //run the query 
  
      if (!$result) {
          $data['success'] = false;
          $data['title'] = $blogTitle;
          $data['authorID'] = $authorID;
          $data['content'] = $content;
          $data['image'] = $image;
      } else {
          $data['success'] = true;
          $data['redirect'] = '../pages/blog.php';
      }
  
      echo json_encode($data);
  ?&gt;
  </code></pre>