title: Call a particular PHP Function In same page using AJAX
body: <p>I am creating a widget using PHP, Jquery and Ajax that can upload and crop an Image. When we select an image, and submit the form. The following code is executed, which uploads the image:</p>
  
  <pre><code>&lt;?php
  
      $valid_formats = array("jpg", "png", "gif", "bmp");
      if(isset($_POST['submit']))
          {
              $name = $_FILES['photoimg']['name'];
              $size = $_FILES['photoimg']['size'];
              if(strlen($name))
                  {
                      list($txt, $ext) = explode(".", $name);
                      if(in_array($ext,$valid_formats) &amp;&amp; $size&lt;(1024*1024))
                          {
                              $actual_image_name = time().substr($txt, 5).".".$ext;
                              $tmp = $_FILES['photoimg']['tmp_name'];
                              if(move_uploaded_file($tmp, $path.$actual_image_name))
                                  {
                                      $image="&lt;img src='uploads/".$actual_image_name."' id=\"photo\" style='max-width:500px' &gt;";
  
                                  }
                              else
                                  echo "failed";
                          }
                      else
                          echo "Invalid file formats..!";                 
                  }
              else
                  echo "Please select image..!";
          }
  ?&gt;
  </code></pre>
  
  <p>While submitting form, the page is getting refreshed. I want to do this without page refresh.</p>
  
  <p>Suppose that if I put the above PHP code in a PHP function, without using<br>
    <code>if(isset($_POST['submit']))</code></p>
  
  <p>Then, is there any way, to call the PHP function using AJAX.</p>
  
  <p>Thanks in advance....</p>