--我发现这是从开始的
$.ajax({
type: "POST",
url: "some.php",
data: parameters,
success: function(msg){
alert("nothing");
}
});据我所知,data包含参数。根据单击的按钮,我的参数是不同的。
我猜我可以在某个地方使用this吗?但是如果我需要发送3个值呢?
<input type="button" id="unique-1"> <!-- With values 'test', 3 and 5 -->
<input type="button" id="unique-2"> <!-- With values 'doh2', 8 and 6 -->如果您需要这些信息,我会使用PHP。
谢谢!
发布于 2011-01-24 20:51:47
看看这个小提琴。该按钮将找到它需要提交的表单,序列化数据,并警告该字符串。然后,您只需要使用该字符串作为ajax调用的data选项的参数。
发布于 2011-01-24 21:07:20
这是另一种方法。
你可以这样做。在每个按钮中,将数据(逗号分隔)放在html数据属性中。单击:读取它,拆分它,然后将它作为一个对象发送。在php端,您将收到一个用于$_GET["data[]"]的字符串数组
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js"></script>
<input type="button" class="mybutton" data-mydata="1,2,really" />
<script>
$('.mybutton').click(function() {
var parameters = $(this).attr('data-mydata').split(',');
$.ajax({
type: "POST",
url: "some.php",
data: {data:parameters},
success: function(msg){
alert("nothing");
}
});
});
</script>小提琴:http://jsfiddle.net/qdH7s/
https://stackoverflow.com/questions/4786928
复制相似问题