简体   繁体   English

从函数中提取的 POST 数据

[英]POST Data pulled from function

I have a signature capture script, using JS and Jquery and an HTML canvas.我有一个签名捕获脚本,使用 JS 和 Jquery 以及一个 HTML 画布。

I am processing the signature, converting it to IMAGE/PNG via a PNGURL.我正在处理签名,通过 PNGURL 将其转换为 IMAGE/PNG。 What I would like to do is to POST the resulting PNGURL return.. but I am having a problem.我想要做的是发布结果 PNGURL 返回..但我遇到了问题。 I'm not very familiar with JS, but I have been working on this for about two days.我对 JS 不是很熟悉,但我已经在这方面工作了大约两天。 As you will be able to see I am having a problem posting the hiddenDataURL.如您所见,我在发布 hiddenDataURL 时遇到了问题。 The page posts, forwards to the next page, but hiddenDataURL shows empty.该页面发布,转发到下一页,但 hiddenDataURL 显示为空。 I have tested the JS with an alert to show that the signature is properly converting to a PNGURL, but it either not getting back into the hidden form element correctly, or isn't posting properly to the signatureaccepted.php page properly.我已经用警报测试了 JS,以显示签名正确转换为 PNGURL,但它要么没有正确返回隐藏的表单元素,要么没有正确发布到 signatureaccepted.php 页面。 any help is greatly appreciated.任何帮助是极大的赞赏。

Here are my two pages.这是我的两页。

The JS on a seperate page.单独页面上的 JS。

function signatureSave() {

    var canvas = document.getElementById("newSignature"); // save canvas image as data url (png format by default)
    var dataURL = canvas.toDataURL("image/png", 0.1);
    document.getElementById("hiddenDataURL").value = dataURL;
    document.getElementById("hiddenForm").submit();

};

and the HTML form I'm trying to post.以及我尝试发布的 HTML 表单。

<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <script src="todataurl.js"></script>
    <script src="signature.js"></script>

</head>

<body>

    <div id="canvas">
        <canvas class="roundCorners" id="newSignature" style="position: relative; margin: 0; padding: 0; border: 1px solid #c4caac;"></canvas>
    </div>

    <script>
        signatureCapture();
    </script>
    <form id="hiddenForm" action="signatureaccepted.php" method="POST">
        <input type="hidden" id="hiddenDataURL" />

    </form>

    <button type="button" onclick="signatureSave()">Sign Out</button>

    <button type="button" onclick="signatureClear()">
                Clear signature
            </button>
    </br>
    Saved Image
    </br>
    <img id="saveSignature" alt="Saved image png" />

</body>

</html>

You need the input to have a name attribute for it to be submitted with the form submit您需要输入具有name属性才能与表单提交一起提交

<form id="hiddenForm" action="signatureaccepted.php" method="POST">
  <input type="hidden" id="hiddenDataURL" name="hiddenDataURL"/>

</form>

it does not have to be the same as ID, but in this case it means the least amount of changes for you不必是相同的ID,但在这种情况下,它意味着改变最少的为你

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

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