【问题标题】:Button to generate a link, then to go there with ajax, php, javascript按钮生成一个链接,然后用ajax、php、javascript去那里
【发布时间】:2013-09-23 17:53:50
【问题描述】:

我需要一个按钮来通过 ajax 调用 php 页面。我需要使用 mailto 链接打开客户电子邮件的按钮。 php 页面生成电子邮件,其中包含将凭据传递到安全站点的加密字符串。

基本上,我需要这些事情按以下顺序发生:

点击按钮。 进行ajax调用。 用“mailto:subject=your_secret_link&body=http://securesite.com?authcode=encrytpedstuff”填充href 打开客户的电子邮件。

我试过这个: html部分:

<span id="mailframe"><a href=# id="myemail"><input name="Request Signing via Email"  value="Request Signing via Email" type="button" class="redButton" onclick="sendEmail();"/></a></span>

javascript部分

function sendEmail() {
    var hash=document.getElementById('hash').value;
    var obj=document.getElementById('mailframe');
    var email=document.getElementById('myemail');
    var mailxml = new XMLHttpRequest;

    mailxml.onreadystatechange = function() {

        if ((mailxml.readyState == 4) && ((mailxml.status == 302)|| (mailxml.status == 200))) {
            email.href=mailxml.responseText;
        }
    }

    mailxml.open("GET",'/secure/literature/generateid.php?hash='+hash+'&docid=<?=$docid?>' );
    mailxml.send();
}

它适用于 IE,但不适用于 Firefox。有什么想法吗?

【问题讨论】:

    标签: javascript php html ajax mailto


    【解决方案1】:

    我认为您需要这样的东西(适用于 FireFox 24):

        <script type="text/javascript">
            function sendEmail() {
                var hash=document.getElementById('hash').value;
    
                var email=document.getElementById('myemail');
                var mailxml = new XMLHttpRequest;
    
                mailxml.onreadystatechange = function() {
                    if (mailxml.readyState == 4 && ((mailxml.status == 302) || (mailxml.status == 200))) {
                        window.location.href = mailxml.responseText;
                    }
                };
    
                mailxml.open("GET", "/your/long/url?with=parameters", true);
                mailxml.send();}
        </script>
    
        <div>
            <input type="button" onclick="sendEmail()" value="Send E-mail"/>
            <input type="text" name="hash" id="hash" value="hashValue" />
            <a href="#" id="myemail">E-mail link</a>
        </div>
    

    还要检查代码中的Easiest way to retrieve cross-browser XmlHttpRequest 和大括号。

    【讨论】:

    • 谢谢,但不幸的是,我必须将所有这些保存在一个按钮下。我不能有单独的链接。所以按钮必须按照正确的步骤完成整个过程。
    • 我无法回答我自己的问题,所以我将在这里发布我的发现:我只是在 mailxml 函数中执行 window.location=email.href。代码由 mailto: 链接中的 generateid.php 页面生成,然后页面立即打开链接。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-17
    • 2017-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多