[英]jQuery with html / php form (using ajaxForm) working only once
I've been trying to solve this for a while now and no success. 我已经尝试解决这个问题一段时间了,但没有成功。 Stackoverflow needed!
需要Stackoverflow!
Basically, what the script does is fetch user profile pictures from the database. 基本上,脚本的作用是从数据库中获取用户个人资料图片。 A moderator can see them and click on the "Ban" button, and then the banPeopleProcess.php file has the code to remove the picture from the database etc. Example: http://screencast.com/t/uFtFgKxYx4s
主持人可以看到它们,然后单击“禁令”按钮,然后banPeopleProcess.php文件具有从数据库中删除图片等的代码。示例: http ://screencast.com/t/uFtFgKxYx4s
Each picture is a form, they all have the same form id. 每张图片都是一个表单,它们都有相同的表单ID。 Here's the HTML (in php echo):
这是HTML(在php echo中):
<div>
<form id=\"banPeopleForm\" action=\"banPeopleProcess.php\" method=\"post\">
<input type=\"hidden\" name=\"toid\" value=". $i ." />
<input id=\"banPeopleBtn\" type=\"submit\" name=\"submit\" value=\"BAN\" />
</form>
</div>
The JS currently looks like this: JS当前看起来像这样:
<script type="text/javascript">
function banPeople() {
$('#banPeopleForm').ajaxForm(function() {
$('#banPeopleBtn').hide();
});
}
$(document).ready(function() {
$('#banPeopleBtn').click(function() {
banPeople();
});
});
</script>
Help greatly appreciated guys!! 帮助非常感谢的家伙!
You should prevent form
from submitting php file and use ajax for calling your php.something like that 您应该阻止
form
提交php文件,并使用ajax调用php.something之类的东西
$(document).ready(function() {
$('#banPeopleBtn').click(function(e) {
e.preventDefault();
banPeople();
$.ajax({
type: "POST",
url: "banPeopleProcess.php"
});
});
});
Use different id for each picture. 每张图片使用不同的ID。 use different form id and submit id for each picture.
使用不同的表单ID并为每张图片提交ID。 Make dynamic the javascript id as well as followed $('#banPeopleBtn'+id).hide();
使动态javascript ID以及后面的$('#banPeopleBtn'+ id).hide(); As javascript can not work with same id in same page.
由于javascript不能在同一页面中使用相同的ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.