ajax发送请求到php相同的值 [英] ajax send request to php same value
本文介绍了ajax发送请求到php相同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在向我的php发送一个变量(i)时遇到问题.我的变量i每次都是6,我该如何解决?
I have problem in sending one variable (i) to my php. My variable i is 6 everytime, how can i fix it?
$(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");
}
推荐答案
Pass the i
as data to the handler of the click
event
for (i=1; i<=5; i++){
$('#rate'+ i +'_').click(i, function(e){
sendValue($(this).val(),e.data);
});
}
这篇关于ajax发送请求到php相同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文