通过jqueryajaxphp和数据库获取数据

通过jqueryajaxphp和数据库获取数据,php,html,jquery,ajax,Php,Html,Jquery,Ajax,我的代码没有完全按照我的需要工作,2页php和1个jquery文件通过jQueryAjax获取数据。 第一页名称catfd.php: <input type="checkbox" value="2" class="catcf"> catfd2 <br /> <input type="checkbox" value="35" class="catcf&qu

我的代码没有完全按照我的需要工作,2页php和1个jquery文件通过jQueryAjax获取数据。 第一页名称catfd.php:

 <input type="checkbox" value="2" class="catcf"> catfd2 <br />
 <input type="checkbox" value="35" class="catcf"> catfd35 <br />
 <input type="checkbox" value="22" class="catcf"> catfd22 <br />
 <input type="checkbox" value="133" class="catcf"> catfd133 <br />
 <input type="checkbox" value="28" class="catcf"> catfd28 <br />
 <input type="checkbox" value="33" class="catcf"> catfd33 <br />
 <input type="checkbox" value="55" class="catcf"> catfd55 <br />
 <input type="checkbox" value="44" class="catcf"> catfd44 <br />
这是jQueryAjax文件

$(document).ready(function(){
    $(".catcf").on('click', function() {

        if ($('input.catcf').is(':checked')) {        

              
        var catcf = Number($(this).val());
        
            $(".catcf").val(catcf);

            $.ajax({
                url: 'getvalue.php',
                type: 'post',
                data: {catcf:catcf},
                beforeSend:function(){
                    $(".main-area-courses-continer").html("Looding....");
                },
                success: function(response){

                    // Setting little delay while displaying new content
                    setTimeout(function() {
                        // appending posts after last post with class="post"
                        $(".main-area-courses-continer:last").after(response).show().fadeIn("slow");

                
                        
                    }, 2000);


                }
            });
        


            }
        });


});
代码正在运行,但结果给我的是重复我选择的第一个复选框值,这意味着jquery没有更改class=“catcf”的值,因为每个类都有unic值。我将使用复选框中的多个选项。
我想使用此复选框从数据库中获得不同的结果。

您的问题如下:

$(“.catcf”).val(catcf);

这里发生的事情是,您选择所有复选框(
$(“.catcf”)
),然后将其
属性更改为单击的复选框的值。删除这一行,它将按预期工作。

旁注:构建查询的方式不安全。你对我敞开心扉。你应该使用或代替。现在只是测试,我会记住的,谢谢。哇,这是正确的!,有没有办法在加载后删除Looding word..通过在
success
处理程序(
$(“.main area courses continer”).html(“”
)中将内容设置为空字符串来删除它。此外,它应该是“加载”。完美的,加载后删除它就像进度条一样,数据出来后我不需要它,非常感谢你还有另一个问题我会发布HHH,如果你有时间帮助我,我将非常感谢你。在我公开之后,我会在这里为你提供链接。
$(document).ready(function(){
    $(".catcf").on('click', function() {

        if ($('input.catcf').is(':checked')) {        

              
        var catcf = Number($(this).val());
        
            $(".catcf").val(catcf);

            $.ajax({
                url: 'getvalue.php',
                type: 'post',
                data: {catcf:catcf},
                beforeSend:function(){
                    $(".main-area-courses-continer").html("Looding....");
                },
                success: function(response){

                    // Setting little delay while displaying new content
                    setTimeout(function() {
                        // appending posts after last post with class="post"
                        $(".main-area-courses-continer:last").after(response).show().fadeIn("slow");

                
                        
                    }, 2000);


                }
            });
        


            }
        });


});