从 jquery 签名中保存的 svg 绘图

drawing from saved svg in jquery signature

我正在使用 JQuery UI Signature 库在网站上获取签名。 我可以捕获签名 OK,但是如果我尝试重新绘制签名(使用另存为 SVG),它不起作用。 控制台显示

"Uncaught SyntaxError: Unexpected token < in JSON at position 0"

JSFiddle

var sig='<svg xmlns="https://www.w3.org/2000/svg"><g fill="#ddd"><rect x="0" y="0" width="300" height="100"/><g fill="none" stroke="#000000" stroke-width="2"><polyline points="43.84,15.22 46.84,17.22 49.84,22.22 52.84,28.22 55.84,33.22 59.84,40.22 62.84,54.22 62.84,58.22 62.84,61.22 59.84,65.22 58.84,65.22 58.84,63.22 59.84,57.22 64.84,49.22 79.84,44.22 86.84,44.22 88.84,44.22 89.84,51.22 86.84,56.22 83.84,59.22 71.84,61.22 65.84,61.22 63.84,59.22 61.84,56.22 61.84,54.22 64.84,50.22 102.84,44.22 155.84,41.22 192.84,41.22 233.84,40.22 234.84,40.22"/></g></g></svg>';

$("#theSignature").signature();
$("#theSignature").signature("draw",sig);       

单击您问题中 link 中的 Save/Restore 选项卡,它显示如下:

Extract the signature as a JSON value, and later re-draw it from that value. Alternately you can generate the signature as SVG, or as a data URL in PNG or JPEG format.

所以你可以 save/restore 为 JSON 但你只能保存为 SVG,你不能根据库自己的文档重新加载 SVG 签名。