title: AJAX - Undefined PHP variable
body: <p>I have the following problem, the following script sends a keyword a PHP file hosted in another domain (I already added the CROS headers), this PHP returns me some <code>&quot;echos of different variables&quot;</code> (title, thumbnail, url, etc.) And it works but randomly returns me <code>&quot;Undefined variables&quot;</code>.</p>
  <p>The first thing was to add an <code>if (isset ())</code> to my variables in PHP and the error does not appear anymore but the results returned by my searches are much smaller (Before adding it averaged 10 to 20 results, Now I get 5 results).</p>
  <p>Can this be a problem with my script?</p>
  <p>My form.php</p>
  <pre><code>&lt;form method=&quot;POST&quot; action=&quot;&quot; id=&quot;form-busqueda&quot;&gt;
  &lt;input type=&quot;text&quot; name=&quot;keyword&quot;&gt;
  &lt;button id=&quot;search&quot; name=&quot;search&quot;&gt;Search&lt;/search&gt;
  &lt;div id=&quot;results&quot;&gt;&lt;/div&gt;
              &lt;script&gt;
              jQuery(function($){
                  var pluginUrl = '&lt;?php echo plugin_dir_url( __FILE__ ); ?&gt;' ;
                  $('[id^=&quot;form-busqueda&quot;]').on('submit', function(e) {
                      e.preventDefault();
                      $.ajax({
                          type : 'POST',
                          url  : 'http://localhost/ladoserver/script.php',
                          data : $(this).serialize(),
                          beforeSend: function(){
                              $('#results').html('&lt;img src=&quot;'+pluginUrl+'../../assets/img/loading.gif&quot; /&gt;');
                          }
                      }).done(function(data) {
                          $('#results').html(data);
                      });
                  });
              });
          &lt;/script&gt;
  &lt;/form&gt;
  </code></pre>
  <p><strong>My <code>script.php</code></strong> (dlPage is a function that create cURL connection):</p>
  <pre><code>&lt;?php
  if (isset($_POST['keyword'])) {
      $search = $_POST['keyword'];
      $html = dlPage(&quot;http://example.com/&quot; . $search);
      //where I search and get with simple_html_dom example:
      $video = $videos-&gt;find('div.example2&gt;a', 0);
      $title = $video-&gt;innertext;
      $url = $video-&gt;attr['href'];
      $id = $video-&gt;attr['id'];
      $thumbnail = $video-&gt;find('div.thumb', 0)-&gt;innertext;
      echo $title;
      echo $url;
      echo $id;
      echo $thumbnail[0];
  }
  ?&gt;
  </code></pre>
  <p>I've updated my code, I didn't put all the code because I thought that it isn't relevant, my <code>script.php</code> works fine with pure PHP. The problem appear when I use AJAX.</p>
  <p>I'm getting the following error:</p>
  <blockquote>
  <p>Notice: Undefined variable: title in C:\xampp\htdocs\webs\ladoserver\script.php on line 13</p>
  <p>Notice: Undefined variable: title in C:\xampp\htdocs\webs\ladoserver\script.php on line 13</p>
  <p>Notice: Undefined variable: url in C:\xampp\htdocs\webs\ladoserver\script.php on line 14</p>
  </blockquote>