简体   繁体   English

按钮生成链接,然后使用ajax,php,javascript到那里

[英]Button to generate a link, then to go there with ajax, php, javascript

I need a button to call a php page though ajax. 我需要一个按钮来通过ajax调用php页面。 I need the button to open the client's email with a mailto link. 我需要通过mailto链接打开客户电子邮件的按钮。 The php page generates the email, which consist of an encrypted string that passes credentials to a secured site. php页面生成电子邮件,该电子邮件由一个加密的字符串组成,该字符串将凭据传递到安全站点。

Basically, I need these things to happen in this order: 基本上,我需要这些事情按此顺序发生:

Click the button. 点击按钮。 Make the ajax call. 进行ajax调用。 Populate href with "mailto:subject=your_secret_link&body= http://securesite.com?authcode=encrytpedstuff " Open the client's email. 用“ mailto:subject = your_secret_link&body = http://securesite.com?authcode=encrytpedstuff ”填充href。打开客户的电子邮件。

I've tried this: html part: 我试过了: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 part 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();
}

It works in IE, but not in Firefox. 它适用于IE,但不适用于Firefox。 Any ideas? 有任何想法吗?

I think that you need something like this (works with FireFox 24): 我认为您需要这样的东西(与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>

Also check Easiest way to retrieve cross-browser XmlHttpRequest and braces in code. 还要选中检索跨浏览器XmlHttpRequest和大括号的最简单方法

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

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