What I'm doing is I want to detect which reply button I click and send its index to php.
jQuery:
$(".reply").each(function (index5) {
$(".reply_button").each(function (index_b) {
            if(index_b==index5){
                $(this).on("click",function (e) {
                    e.preventDefault();
                    var $this = $(this)
                    $.ajax({
                        type:"POST",
                        url:"/yyqGS/public/form/reply.php",
                        data:{index:index_b},
                        dataType: "json",
                        success:function (d) {
                            console.log(d);
                        }
                    });
                })
            }
        });
});
PHP:
 <?php 
    $n = $_POST['index'];
    echo $n+1;
I want to pass the variable index_b to php the file, so that $_POST['index'] can get the value.
But the result on php page is 1, which means it doesn't get the value of index_b from ajax.
On the other hand, what is showed on console is, HOWEVER, correct number! Like, if I click the first reply button, it shows 1, if I click second, it shows 2, and so on...
result on php: always 1.
result on console: correct number.
I couldn't figure out how it happened!
UPDATE: so i changed console.log() to submit(), i want ajax would send the index to php first, and then another a form will send like 'text' i type to php. But, what's on php page is still 1.
$this.parent() is a form.
So what i really want to do is i want to send the variable index_b to php, and also, at the same time, send those input data to php. So i can use them both.
$(".reply_button").each(function (index_b) {
            if(index_b==index5){
                $(this).on("click",function (e) {
                    e.preventDefault();
                    var $this = $(this)
                    $.ajax({
                        type:"POST",
                        url:"/yyqGS/public/form/reply.php",
                        data:{index:index_b},
                        success:function (d) {
                            $this.parent().submit();
                        }
                    });
                })
            }
        });
 
    