dongmu3187 2013-09-23 17:53 采纳率: 0%
浏览 35

按钮生成一个链接,然后去那里用ajax,php,javascript

I need a button to call a php page though ajax. I need the button to open the client's email with a mailto link. The php page generates the email, which consist of an encrypted string that passes credentials to a secured site.

Basically, I need these things to happen in this order:

Click the button. Make the ajax call. Populate href with "mailto:subject=your_secret_link&body=http://securesite.com?authcode=encrytpedstuff" Open the client's email.

I've tried this: html part:

<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

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. Any ideas?

  • 写回答

1条回答 默认 最新

  • dongyi3616 2013-09-23 18:28
    关注

    I think that you need something like this (works with 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.

    评论

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等