简体   繁体   English

Ajax - HTML5 Canvas

[英]Ajax - HTML5 Canvas

I've never used ajax before and I guess I'm struggling with the idea and how it works. 我之前从未使用过ajax,我想我正在努力解决这个想法以及它是如何工作的。

What I want to do: 我想做的事:

I want to draw all over my canvas and hit save. 我想在我的画布上绘制并点击保存。 Saving will send the dataURL to my mySQL database. 保存会将dataURL发送到mySQL数据库。

Hear is what I've read: This is impossible without Ajax 听到的是我读过的内容:如果没有Ajax,这是不可能的

What I've found: Nothing to make me understand how this can work with Ajax. 我发现:没有什么可以让我理解这对Ajax有什么用处。

To pull the dataURL (information drawn on the canvas) I'm currently trying to use the Signature-Pad lab to attempt to do what I want to do 要拉出dataURL(在画布上绘制的信息)我正在尝试使用Signature-Pad实验室尝试做我想做的事情

If anyone will help me out it would be much appreciated. 如果有人会帮助我,我将不胜感激。 Whether it be working ajax code on how this can work, and idea on how it can work, or anything relative links. 是否正在使用ajax代码来了解它如何工作,以及它是如何工作的想法,或任何相关链接。

Also, I'm using PHP and Javascript. 另外,我正在使用PHP和Javascript。

Create a <form action="post"> on the page with a hidden <input> element. 在页面上使用隐藏的<input>元素创建<form action="post"> When you want to upload the image, call canvas.toDataURL() which will return a string of image data in the format data:image/png;base64,… . 如果要上传图像,请调用canvas.toDataURL() ,它将返回格式为data:image/png;base64,…的图像数据字符串。 Then set the value of the hidden input to that string and submit the form. 然后将隐藏输入的值设置为该字符串并提交表单。 On the server side, strip the data: header and Base64 decode the rest of the string, then save that string as you would with any other image data (eg, to a file). 在服务器端,剥离data: header和Base64解码其余字符串,然后像保存任何其他图像数据一样保存该字符串(例如,保存到文件)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM