title: Requesting Video From Apple
body: <p>I am a complete newbie to programming and am working on a sample project. I am trying to send an AJAX request to Apple to get a video from a user-defined artist. However, I don't get any data returned to my function and nothing shows up in the console.</p>
  
  <p>Index.php</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;iTunes Video Search&lt;/title&gt;
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
          $(document).ready(function() {
              $('form').submit(function() {
                  $.post($(this).attr('action'), $(this).serialize(), function(res) {
                      var htmlStr = '';
                      if (res.results.length !== 0) {
                          htmlStr += "&lt;video controls src='" + res.results[0].previewUrl + "'&gt;&lt;/video&gt;";
                      } else {
                          htmlStr += "Not Found";
                      }
                      $('#video').html(htmlStr);
                  }, 'json');
                  return false;
              });
          });
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h2&gt;Enter Artist's Name&lt;/h2&gt;
      &lt;form action="/videos/create" method="post"&gt;
          &lt;input type="search" name="artist_name" id="artist_name"&gt;
          &lt;input type="submit" value="Search"&gt;
      &lt;/form&gt;
      &lt;div id="video"&gt;&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Videos.php</p>
  
  <pre><code>&lt;?php
  
  class Videos extends CI_Controller {
  
      public function index() {
          $this-&gt;load-&gt;view('index');
      }
  
      public function create() {
          $artist_name = str_replace(' ', '', $this-&gt;input-&gt;post('artist_name'));
          $url = "https://itunes.apple.com/search?term=" . $artist_name . "&amp;entity=musicVideo";
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
          curl_setopt($ch, CURLOPT_URL, $url);
          curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
          $data = curl_exec($ch);
          $info = curl_getinfo($ch);
          curl_close($ch);
          echo $data;
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p>Any help is greatly appreciated!</p>