2

scheme:user draws in canvas, canvas converted to image (png or jpeg), converted file is saved in specific dir on server, after drawing canvas user clicks button, all i could do is:

  function to_image(){
            var canvas = document.getElementById("canvas");
            var data = canvas.toDataURL('image/png');}

how i can perform this task? (is there any way to do it without AJAX or not?)

joebeeson
  • 4,159
  • 1
  • 22
  • 29
bla2eOD
  • 77
  • 6
  • You've tagged this with `jQuery`, why wouldn't you want to use Ajax? You already have a JS dependency.. – Fabrício Matté May 01 '13 at 19:51
  • @FabrícioMatté right, i just thought about keeping external libraries count as low as possible, but guess nowdays it is not so easy – bla2eOD May 01 '13 at 20:02

1 Answers1

1

You'll have to submit it to the server using a form and/or ajax. JavaScript is run at clientside, so its not able to interfere with the server directly.

Edit: You could maybe find something usefull here, if you need more info on how to do this: Uploading 'canvas' image data to the server

Community
  • 1
  • 1
Daniel Mensing
  • 956
  • 5
  • 13
  • ok, and another question, is it better to store that canvas as img than base64? and where should i store base64 if i preffer to use it? – bla2eOD May 01 '13 at 19:53
  • @bla2eOD: Technically another question, but it depends what you wish to do with it in future. If you are only saving it to send it back to the browser, then maybe keep it in that format. Otherwise decode it to the png or whatever format you have generated the base64 data in. I would have a tendency to save it as the actual file type regardless of need. – Orbling May 01 '13 at 19:56