Note that there are some explanatory texts on larger screens.

plurals
  1. POWindow won't popup in AJAX
    primarykey
    data
    text
    <p>I followed this tutorial: <a href="http://www.youtube.com/watch?v=qUjQrThw-ss" rel="nofollow">http://www.youtube.com/watch?v=qUjQrThw-ss</a></p> <p>I use xampp to test it out.</p> <p>The problem is that the window won't popup there.</p> <p>This is my code:</p> <p><strong>HTML:</strong></p> <pre><code>&lt;!doctype html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Html5 Drawing App!&lt;/title&gt; &lt;link rel="stylesheet" type="text/css" href="style.css"&gt; &lt;/head&gt; &lt;body style='margin: 0'&gt; &lt;div id="toolbar"&gt; &lt;div id="rad"&gt; Radius &lt;span id="radval"&gt;10&lt;/span&gt; &lt;div id="decRad" class="radcontrol"&gt;-&lt;/div&gt; &lt;div id="incRad" class="radcontrol"&gt;+&lt;/div&gt; &lt;/div&gt; &lt;div id="colors"&gt; &lt;/div&gt; &lt;div id="save"&gt; Save &lt;/div&gt; &lt;/div&gt; &lt;canvas id="canvas" style="display: block;"&gt; Sorry, Your Browser Is Unsupported. Switch To Another Browser &lt;/canvas&gt; &lt;script src="main.js"&gt;&lt;/script&gt; &lt;script src="radius.js"&gt;&lt;/script&gt; &lt;script src="colors.js"&gt;&lt;/script&gt; &lt;script src="save.js"&gt;&lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>save.js:</strong></p> <pre><code>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 &amp;&amp; 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'); } </code></pre> <p><strong>save.php:</strong></p> <pre><code>&lt;?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"); } ?&gt; </code></pre> <p>Why isnt it popping up? Using Google Chromes developer tools, I get the following error:</p> <pre><code>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 </code></pre> <p>Please help me fix this. Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload