title: How doo I resolve getting a 500 error when calling $.post
body: <p>My website has a drawing tool. This drawing tool help met create an image (.png) from the drawing. Has been working for years now, but recently changed the wordpress theme.</p>
  <p>Now I can't figure out what's going wrong.</p>
  <p>I have the following code which is doing a POST request to a file in my theme folder</p>
  <pre><code>var templateUrl = 'https://example.nl/wp-content/themes/generatepress';
    var strDataURI = canvas.toDataURL(&quot;image/jpg&quot;,'',1.0);
    var jsnDataJSON = encodeURIComponent(JSON.stringify(canvas));
    $('input[name=json]').val(jsnDataJSON);
    strDataURI = strDataURI.substr(22, strDataURI.length);
  
    var ajax_urll= templateUrl+&quot;/ajax.php&quot;;   
    
          $.post(ajax_urll,
          { 
              str: strDataURI
          },
          function(data){
              var obj=jQuery.parseJSON(data);
              if(obj.status!=&quot;ERROR&quot;){
              jQuery(&quot;#drawing&quot;).html(obj.image);
              jQuery(&quot;#drawingsaveresult&quot;).html(&quot;Drawing has been successfully saved&quot;);
              jQuery(&quot;#drawingsaveresult&quot;).fadeOut(10000);
              jQuery(&quot;input[name='drawing']&quot;).val(obj.imagename);
              }else{
                  jQuery(&quot;#drawingsaveresult&quot;).html(&quot;Else error in saving drawing&quot;);
                  jQuery(&quot;#drawingsaveresult&quot;).fadeOut(10000);
                  }
          });
  </code></pre>
  <p>So this code is calling ajax.php file (file in theme folder) which does the following</p>
  <pre><code>&lt;?php
  session_start();
  
  // require_once( $_SERVER['DOCUMENT_ROOT'] . '/example.nl/wp-load.php' ); localhost
  require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );
  
  global $wpdb;
  
  $data = base64_decode($_POST[&quot;str&quot;]);
  
  $urlUploadImages = &quot;oefeningen/&quot;;
  
  $nameImage = rand().&quot;drawing.png&quot;;
  
  $img = imagecreatefromstring($data);
  
  imageAlphaBlending($img, true);
  
  imageSaveAlpha($img, true);
  $response=array();
  if($img) {
      imagepng($img, $urlUploadImages.$nameImage, 0);
      imagedestroy($img);
      get_stylesheet_directory_uri(); 
      $response['image']=&quot;&lt;img src='&quot;.get_stylesheet_directory_uri().&quot;/oefeningen/&quot;.$nameImage.&quot;' width=100 height=150&gt;&quot;;
      $response['imagename']=$nameImage;
      $response['status']=&quot;success&quot;;
      
  }
  else {
      $response['status']=&quot;ERROR&quot;;
  }
  
  
  echo json_encode($response);
  </code></pre>
  <p>But for some reason it's not working anymore. In the console it's giving the following error back
  POST <a href="https://example.nl/wp-content/themes/generatepress/ajax.php" rel="nofollow noreferrer">https://example.nl/wp-content/themes/generatepress/ajax.php</a> 500</p>
  <p>I can't find a resolution. Can someone assist me with this?</p>