Javascript 使用dataURL发送变量
嗨,我有这段代码,它可以将一个dataURL发送到php并保存到服务器 JS: PHPJavascript 使用dataURL发送变量,javascript,php,Javascript,Php,嗨,我有这段代码,它可以将一个dataURL发送到php并保存到服务器 JS: PHP 有人知道为什么吗?试试这个: type:"POST", url: "php/save.php", data: { img_val: canvas.toDataURL("image/png"), random: random }, success: function(){ $\u
有人知道为什么吗?试试这个:
type:"POST",
url: "php/save.php",
data: {
img_val: canvas.toDataURL("image/png"),
random: random
},
success: function(){
$\u POST
包含img\u val
和random
键这是正确的,在发布的代码片段中,数据URL没有名称是的,这很有效,谢谢!我会在几分钟内接受。
//Show the image
echo '<img src="'.$_POST['img_val'].'" />';
//Get the base-64 string from data
$filteredData=substr($_POST['img_val'], strpos($_POST['img_val'], ",")+1);
//Decode the string
$unencodedData=base64_decode($filteredData);
//Save the image
file_put_contents('img.png', $unencodedData);
?>
type:"POST",
url: "php/save.php",
data: $('#img_val').val(canvas.toDataURL("image/png"))+"&random="+random,
success: function(){
<?php
//save.php code
$random = $_REQUEST['random'];
//Show the image
echo '<img src="'.$_POST['img_val'].'" />';
//Get the base-64 string from data
$filteredData=substr($_POST['img_val'], strpos($_POST['img_val'], ",")+1);
//Decode the string
$unencodedData=base64_decode($filteredData);
//Save the image
file_put_contents($random.'img.png', $unencodedData);
?>
type:"POST",
url: "php/save.php",
data: {
img_val: canvas.toDataURL("image/png"),
random: random
},
success: function(){