$(".form").click(function(){
$.post(
'/forms/ajax.php',{
id:form.id.value
},
function(output){
$('#ajax').html(output).fadeIn(50)}, 500);
}
);
$n=1;
while(//LOOP ALL LIST FROM DB){
echo"
<form id='form' class='form'>
<div class='content'>".$n.". ".$title[$n-1]."</div>
<input type='hidden' name='id' value='".$id."'/>
</form>
";
$n++
}
我有一个页面使用while循环来循环所有列表,每个列表可以点击比jquery将数据发布到另一个页面&amp;发回数据。
我的问题是如何为所有列表使用一个$ post脚本。
离。如果list_1单击,则发布list_1的数据。如果list_3单击,它将发布list_3的数据
答案 0 :(得分:0)
this
指的是dom元素,因此$(this).submit()
或$(this).serialize()
之类的调用将发布表单或为您提供带有表单内容的序列化字符串。
$('.form').on('submit', function(e) {
e.preventDefault(); // prevents form from submitting
$.post('/form/ajax.php', { $(this).serialize() }, function(output) {
$('#ajax').html(output).fadeIn(50);
});
});
可以在this fiddle
中找到警告序列化数据的示例