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.
Now I can't figure out what's going wrong.
I have the following code which is doing a POST request to a file in my theme folder
var templateUrl = 'https://example.nl/wp-content/themes/generatepress';
var strDataURI = canvas.toDataURL("image/jpg",'',1.0);
var jsnDataJSON = encodeURIComponent(JSON.stringify(canvas));
$('input[name=json]').val(jsnDataJSON);
strDataURI = strDataURI.substr(22, strDataURI.length);
var ajax_urll= templateUrl+"/ajax.php";
$.post(ajax_urll,
{
str: strDataURI
},
function(data){
var obj=jQuery.parseJSON(data);
if(obj.status!="ERROR"){
jQuery("#drawing").html(obj.image);
jQuery("#drawingsaveresult").html("Drawing has been successfully saved");
jQuery("#drawingsaveresult").fadeOut(10000);
jQuery("input[name='drawing']").val(obj.imagename);
}else{
jQuery("#drawingsaveresult").html("Else error in saving drawing");
jQuery("#drawingsaveresult").fadeOut(10000);
}
});
So this code is calling ajax.php file (file in theme folder) which does the following
<?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["str"]);
$urlUploadImages = "oefeningen/";
$nameImage = rand()."drawing.png";
$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']="<img src='".get_stylesheet_directory_uri()."/oefeningen/".$nameImage."' width=100 height=150>";
$response['imagename']=$nameImage;
$response['status']="success";
}
else {
$response['status']="ERROR";
}
echo json_encode($response);
But for some reason it's not working anymore. In the console it's giving the following error back
POST https://example.nl/wp-content/themes/generatepress/ajax.php 500
I can't find a resolution. Can someone assist me with this?
question from:
https://stackoverflow.com/questions/65885840/how-doo-i-resolve-getting-a-500-error-when-calling-post 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…