我遵循了本教程:http://www.youtube.com/watch?v=qUjQrThw-ss
我使用xampp来测试它。
问题是该窗口不会弹出窗口。
这是我的代码:
HTML:
<!doctype html>
<html>
<head>
<title>Html5 Drawing App!</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body style='margin: 0'>
<div id="toolbar">
<div id="rad">
Radius <span id="radval">10</span>
<div id="decRad" class="radcontrol">-</div>
<div id="incRad" class="radcontrol">+</div>
</div>
<div id="colors">
</div>
<div id="save">
Save
</div>
</div>
<canvas id="canvas" style="display: block;">
Sorry, Your Browser Is Unsupported. Switch To Another Browser
</canvas>
<script src="main.js"></script>
<script src="radius.js"></script>
<script src="colors.js"></script>
<script src="save.js"></script>
</body>
</html>
save.js:
var saveButton = document.getElementById('save');
saveButton.addEventListener('click', saveImage);
function saveImage(){
var data = canvas.toDataURL();
var request = new XMLHttpRequest();
request.onreadystatechange = function(){
if(request.readyState == 4 && request.status = 200){
//do our stuff
var response = request.responseText;
window.open(response, '_blank', 'location=0, menubar=0');
}
}
request.open('POST', 'save.php', true);
request.setRequestHeader('Content-type', 'application/x-ww-form-urlencoded');
request.send('img='+data);
//window.open(data, '_blank', 'location=0, menubar=0');
}
save.php:
<?php
$data = $_POST_['img'];
$data = str_replace('data:image/png;base64', '', $data);
$data = str_replace(' ', '+', $data);
$img = base64_decode($data);
$path = 'images/' . uniqid() . '.png';
if(file_put_contents($path, $img)){
print $path;
}else{
header("HTTP/1.1 500 Internal Server Error");
}
?>
为什么不突然冒出来? 使用Google Chromes开发人员工具,我收到以下错误:
Uncaught ReferenceError: Invalid left-hand side in assignment save.js:11
POST http://localhost/draw/save.php 500 (Internal Server Error) save.js:20
3
Uncaught ReferenceError: Invalid left-hand side in assignment
请帮我解决这个问题。感谢
答案 0 :(得分:0)
您在此行中省略了等号:
if(request.readyState == 4 && request.status = 200){
^ should be ==
答案 1 :(得分:0)
尝试修复以下错误:
if(request.readyState == 4 && request.status = 200){
Λ
|___ ==
request.setRequestHeader('Content-type', 'application/x-ww-form-urlencoded');
Λ
|___ www
$data = $_POST_['img'];
Λ
|___ $_POST[...