Php $ _POST [’data’. $ I] increases the number &gra…

Maybe this is a strange question. I have many button pass value with jquery. they are very similar. so i tried to combine them with number increase.

index.php


jQuery(document).ready(function(){
for (var i = 0; i <5; i++){
    $('.click'+i).click(function(){
        $.ajax({
            url: "data.php",
            dataType: "html",
            type: 'POST',
            data: "data"+i+"="+i,
            success: function(data){
                $("#result"+i).html(data);
            }
        });
    });
}
});


aaa
bbb
ccc
ddd
eee
<?php
for ($i=1; $i<=5; $i++){
echo '
'; } ?>

but $_POST['data'.$i]
is an unexpected T_ECHO, so how to write so that I will not reapeat work in data.php

data.php

<?php
for ($i=1; $i
for ($i=1; $i<=5; $i++){
    echo $_POST['data'.$i];
}

is ok

Also it’s possible to use data[]
or data[5]
as field name.

It will be available in array
$_POST['data']

Hello, buddy!责编内容来自:Hello, buddy! (源链) | 更多关于

阅读提示:酷辣虫无法对本内容的真实性提供任何保证,请自行验证并承担相关的风险与后果!
本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 综合编程 » Php &dollar; &lowbar;POST &lbrack;’data’&period; &dollar; I&rsqb; increases the number &gra…

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录