ajax向php发送相同值的请求
我无法将一个变量(I)发送到我的php。 我的变量i每次都是6,我如何修正它ajax向php发送相同值的请求,php,ajax,request,send,Php,Ajax,Request,Send,我无法将一个变量(I)发送到我的php。 我的变量i每次都是6,我如何修正它 $(document).ready(function(){ for (i=1; i<=5; i++){ $('#rate'+ i +'_').click(function(){ sendValue($(this).val(),i); }); } }); function sendValue(str,str2){ $.post("/php/test.php",{ sendValue: str
$(document).ready(function(){
for (i=1; i<=5; i++){
$('#rate'+ i +'_').click(function(){
sendValue($(this).val(),i);
});
}
});
function sendValue(str,str2){
$.post("/php/test.php",{ sendValue: str, sendValue2 : str2 },
function(data){
$('#display').html(data.returnValue);
}, "json");
}
$(文档).ready(函数(){
对于(i=1;i将i
作为数据传递给事件处理程序
有关(i=1;i)的详细说明,请参见。
for (i=1; i<=5; i++){
$('#rate'+ i +'_').click(i, function(e){
sendValue($(this).val(),e.data);
});
}