title: having trouble using JavaScript or Ajax and text display the same page
body: <p>I'm having mistakes do not know where error</p>
  
  <p>Having trouble using JavaScript or Ajax and text display the same page</p>
  
  <p>Please help me in the wrong reform</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;pop up example&lt;/title&gt;
  
      &lt;script src="//code.jquery.com/jquery-1.11.2.min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
          document.getElementById('myform').addEventListener("submit",upload);
  function upload()
  {
      var xhr = new XMLHttpRequest();
      xhr.open("POST","/upload.php",true);        
      {
          var formdata = new formData(myform);
          xhr.send(formdata);
      }
      xhr.onreadystatechange = function(){
      if(xhr.readyState == 4 &amp;&amp; xhr.status == 200)
      {
               //some code to check if submission succeeded 
               url = xhr.responseText();
               if(url == 'failed')
                    Console.log('upload failed'); // do something for failure
               else
                    document.getElementById('urlBox').innerHTML = url;
      }
  }; return false;
  }
      &lt;/script&gt;
  &lt;/head&gt;
  
  
  &lt;body&gt;
  
  
  
  &lt;form id="myform" method="POST" action=&lt;?php ($_SERVER["PHP_SELF"]); ?&gt;&gt;
  
      &lt;p&gt;chose url: 
      &lt;select size="1" name="D1"&gt;
          &lt;option value="google_drive"&gt;google drive&lt;/option&gt;
          &lt;option value="clody"&gt;clody&lt;/option&gt;
      &lt;/select&gt;    
      &lt;input type="text" name="T1" size="40"&gt;    
      &lt;input type="submit" value="go" name="B1"&gt;
      &lt;input type="reset" value="reset" name="B2"&gt;
      &lt;/p&gt;
  &lt;/form&gt;
  
  
   &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>and this upload.php file</p>
  
  <pre><code>&lt;?php
  if(!empty($_POST['D1']) &amp;&amp; !empty($_POST['T1'])){
      $providers = array(
          'google_drive' =&gt; 'Goole drive^https://drive.google.com/file/d/{replace}/view',
          'clody' =&gt; 'Cloudy^https://www.cloudy.ec/embed.php?id={replace}'        
      );
  
      if(isset($providers[$_POST['D1']])){
  
          $url =  str_replace('{replace}', $_POST['T1'], $providers[$_POST['D1']]);
          echo "$url";
      }
  }
  
  else{
     echo "failed";
  }
  ?&gt;
  </code></pre>
  
  <p>and thank you all</p>