从onclick函数将方法发布到URL [英] Post Method to URL from a onclick function

查看:43
本文介绍了从onclick函数将方法发布到URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些听起来很简单但对我来说很困难的事情上,我需要帮助.因此,当有人点击该div时:

I need help on something that sounds easy but is difficult for me. So when someone clicks on this div:

<div onclick="<go to url sending data using the post method>">Click Me</div>

我希望它将数据发送到一个PHP文件,该文件将接收我想要的信息.我会使用GET函数,但听说它很容易被黑客入侵.如果他们是更简单的解决方案或更安全的解决方案,请帮助我.

I want it to send data to a PHP file that will take the information that i want it to. I would use the GET function but I have heard that its easily hackable. If their is a lot simpler solution or something more secure please help me out.

推荐答案

如果您需要使用div,可以这样做,但是我建议您使用按钮或类型为commit的输入.

If you need to use div you can do it like this but I suggest that you use button or input of type submit.

<form id="form-id" method="post" action="your-php-file-url">
<input type="hidden" name="your-variable-name" value="your-variable-value">
<div onclick="document.getElementById('form-id').submit();">Click Me</div>
</form>

您也可以使用jQuery或其他JS库.

Also you may use jQuery or some other JS library.

注意:请记住,如果通过浏览器提供您发送的数据,则操作起来真的很容易(如果使用POST或GET则不重要),因此将其签出非常重要当您处理它时.

NOTE: Keep in mind that if the data that you send is provided via browser it's really easy to manipulate (doesn't mater if you use POST or GET) so it's important to check it out when you process it.

这篇关于从onclick函数将方法发布到URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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