Wisp Ever
Wisp Ever

Reputation: 37

ajax send request to php same value

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");
}  

Upvotes: 0

Views: 248

Answers (1)

Musa
Musa

Reputation: 97707

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);
    });
}

Upvotes: 1

Related Questions