我想使用ajax发布画布图像数据和测试。但我不能。我是怎么做到的?这些是以下代码:
$("#connect").on('click', function (e) {
e.preventDefault();
var imgData = getCanvas.toDataURL("image/png");
var message = $("#msg").val();
var data = new FormData();
data.append('imagedata', imgData);
data.append('msg', message);
var xhr = new XMLHttpRequest();
xhr.open("POST", 'photoappcode.php', false);
xhr.setRequestHeader('Content-Type', 'application/upload');
xhr.send(data);
});
$imageData=$GLOBALS['HTTP_RAW_POST_DATA'];
$msg = $_POST['msg'];
if(!empty($imageData)){
$fileNo = time();
$filteredData=substr($imageData, strpos($imageData, ",")+1);
$unencodedData=base64_decode($filteredData);
$fp = fopen("images/image_".$fileNo.".png", 'wb' );
fwrite( $fp, $unencodedData);
$path_parts = basename($fp);
fclose( $fp );
}
echo $imageData;
echo $msg;
这里我无法从ajax调用中获取值。请帮忙。