通过链接导航到另一个页面,发送邮件请求 [英] navigate to another page with post request through link

查看:136
本文介绍了通过链接导航到另一个页面,发送邮件请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>    
<script type="text/javascript">
    function DoPost(){
      $.post("index.html", { name: "John", time: "2pm" } );
   }
    </script>
</head>

<body>
<a href="javascript:DoPost()">GO</a>

</body>
</html>

我做了函数并试图调用那个函数,在那个函数里我提到了url和data <这里有一个href =http://api.jquery.com/jQuery.post/>。但是,它并不适合我。

I made function and trying to call that function, inside that function I mentioned url and data as mentioned here. But, It's not working for me.

注意:即使我在我的帖子标题中提到,那么我也想澄清一点,我想要使用 POST 方法通过简单的超链接导航到另一个页面。

NOTE : Even I mentioned in my post title, then also I want to clarify that, I want to navigate to another page using POST method through simple hyperlink.

推荐答案

创建一个包含您需要发送的所有数据的html表单,并指定您需要转发用户的页面。

Create an html form with all the data you need to send and specify as action the page you need to forward the user.

<form method="post" id="theForm" action="REDIRECT_PAGE.php">

然后在该表单中放置一些隐藏字段。

Then put some hidden fields in that form.

<input type="hidden" name="name" value="John">
<input type="hidden" name="time" value="2pm">
</form>

把你的doRedirect函数放在里面,重定向在正确提交你的POST数据时工作。 p>

Wrap this inside of your doRedirect function and the redirect will work while correctly submitting your POST data.

document.getElementById('theForm').submit()






请注意,如果您需要将用户重定向到.php页面而不是.html页面读取POST数据。这取决于您的服务器配置,但默认情况下,我认为您不能在.html文件中运行PHP代码。


As a side note, you may want to redirect the user to a .php page not a .html one if you need to read POST data. This depends on your server configuration but, by default, I don't think you can run PHP code inside of a .html file.

这篇关于通过链接导航到另一个页面,发送邮件请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆