Php AJAX请求错误

Php AJAX请求错误,php,jquery,ajax,Php,Jquery,Ajax,最终编辑-回答:谢谢大家的帮助。最后,它归结为在更改url名称时出现了一些htaccess问题,并且由于一些奇怪的原因,即使在引用根(./ajax)时,它也不喜欢它。我不知道为什么,但它就是没有。当我硬编码整个URL时,它工作了。荒谬-谢谢大家的帮助。每天都是上学的日子 我一辈子都搞不懂为什么会出错-有人能再看一眼吗-这可能是很愚蠢的事情,提前谢谢你的帮助: 编辑我愚蠢地输入了错误的URL-但是。。。现在我已经输入了正确的URL,该网站只是挂起和崩溃。有什么想法吗 编辑2为了给这篇文章添加更多的

最终编辑-回答:谢谢大家的帮助。最后,它归结为在更改url名称时出现了一些htaccess问题,并且由于一些奇怪的原因,即使在引用根(./ajax)时,它也不喜欢它。我不知道为什么,但它就是没有。当我硬编码整个URL时,它工作了。荒谬-谢谢大家的帮助。每天都是上学的日子

我一辈子都搞不懂为什么会出错-有人能再看一眼吗-这可能是很愚蠢的事情,提前谢谢你的帮助:

编辑我愚蠢地输入了错误的URL-但是。。。现在我已经输入了正确的URL,该网站只是挂起和崩溃。有什么想法吗

编辑2为了给这篇文章添加更多的细节,“加载…”div出现,因此ajax肯定会启动,然后页面崩溃并没有响应。我添加了额外的验证以确保PHP文件存在。是的。PHP文件只是回显一个h1标记。这是一个完全的谜,因为我昨天在一个家庭服务器上做了一个类似的ajax请求,它工作得很好

编辑3感谢大家迄今为止在这方面的投入和帮助。经过进一步测试,我已经从jQueryAjax请求中删除了数据属性,但它仍然完全没有响应并崩溃。这可能与服务器有关吗?我真的没有主意了

HTML:


JQuery:

$('input[type="checkbox"]').change(function(){

    var name = $(this).attr("name");
    var ProdCatFil = [];
    var ProdSubCatFil = [];
    var BrandFil = [];

    // Loop through the checked checkboxes in the same group
    // and add their values to an array
    $('input[type="checkbox"]:checked').each(function(){

        switch(name) {

            case 'ProdCatFil[]': 
                ProdCatFil.push($(this).val());
            break;
            case 'ProdSubCatFil[]': 
                ProdSubCatFil.push($(this).val());
            break;
            case 'BrandFil[]': 
                BrandFil.push($(this).val());
            break;
        }
    });

    $("#loading").ajaxStart(function(){
        $(this).show();
        $('.content_area').hide();
    });

    $("#loading").ajaxStop(function(){
        $(this).hide();
        $('.content_area').show();
    });

    $.ajax({
        type: "GET",
        url: '../ajax/ajax.php',
        data: 'ProdCatFil='+ProdCatFil+'&ProdSubCatFil='+ProdSubCatFil+'&BrandFil='+BrandFil,
        success: function(data) {
            $('.content_area').html(data);
        }       
    }).error(function (event, jqXHR, ajaxSettings, thrownError) {
        $('.content_area').html("<h2>Could not retrieve data</h2>");
        //alert('[event:' + event + '], [jqXHR:' + jqXHR + '], [ajaxSettings:' + ajaxSettings + '], [thrownError:' + thrownError + '])');
    });

});
$('input[type=“checkbox”]”)。更改(函数(){
var name=$(this.attr(“name”);
var ProdCatFil=[];
var prodspactfil=[];
var BrandFil=[];
//循环检查同一组中的复选框
//并将其值添加到数组中
$('input[type=“checkbox”]:checked')。每个(函数(){
交换机(名称){
案例“ProdCatFil[]”:
prodcafil.push($(this.val());
打破
案例“ProdSubCatFil[]”:
prodsubatfil.push($(this.val());
打破
案例“BrandFil[]”:
BrandFil.push($(this.val());
打破
}
});
$(“#加载”).ajaxStart(函数(){
$(this.show();
$('.content_area').hide();
});
$(“#加载”).ajaxStop(函数(){
$(this.hide();
$('.content_area').show();
});
$.ajax({
键入:“获取”,
url:“../ajax/ajax.php”,
数据:“ProdCatFil=”+ProdCatFil+”&prodspactfil=“+prodspactfil+”&BrandFil=”+BrandFil,
成功:功能(数据){
$('.content_area').html(数据);
}       
}).错误(函数(事件、jqXHR、ajaxSettings、thrownError){
$('.content_area').html(“无法检索数据”);
//警报('[event:'+event+']、[jqXHR:'+jqXHR+']、[ajaxSettings:'+ajaxSettings+']、[thrownError:'+thrownError+']);
});
});
PHP(只是为了证明它工作正常):

echo“测试”;

一切正常,但你还是错了。。。 请参见您的
数据:
属性:

$.ajax({
    type: "GET", // The get ajax type cannot send data as post
    url: '../ajax/ajax.php',
    data: 'ProdCatFil='+ProdCatFil+'&ProdSubCatFil='+ProdSubCatFil+'&BrandFil='+BrandFil,
    success: function(data) {
        $('.content_area').html(data);
    }       
}).error(function (event, jqXHR, ajaxSettings, thrownError) {
    $('.content_area').html("<h2>Could not retrieve data</h2>");
    //alert('[event:' + event + '], [jqXHR:' + jqXHR + '], [ajaxSettings:' + ajaxSettings + '], [thrownError:' + thrownError + '])');
});

如果您没有添加错误的右大括号,请尝试此操作…

//添加document ready函数并删除复选框周围的双大括号。它应该是$('input[type=checkbox]')。更改(函数(){在两个位置

$('input[type=checkbox]').change(function(){

    var name = $(this).attr("name");
    var ProdCatFil = [];
    var ProdSubCatFil = [];
    var BrandFil = [];

    // Loop through the checked checkboxes in the same group
    // and add their values to an array
    $('input[type=checkbox]:checked').each(function(){

        switch(name) {
           case 'ProdCatFil[]': 
                ProdCatFil.push($(this).val());
                break;
           case 'ProdSubCatFil[]': 
                ProdSubCatFil.push($(this).val());
                break;
           case 'BrandFil[]': 
                BrandFil.push($(this).val());
                break;
        }

    });


    $("#loading").ajaxStart(function(){
        $(this).show();
        $('.content_area').hide();
    });

    $("#loading").ajaxStop(function(){
        $(this).hide();
        $('.content_area').show();
    });

    $.ajax({
        type: "GET",
        url: '../ajax/ajax.php',
        data: 'ProdCatFil='+ProdCatFil+'&ProdSubCatFil='+ProdSubCatFil+'&BrandFil='+BrandFil,
        success: function(data) {
            $('.content_area').html(data);
        }       
    }).error(function (event, jqXHR, ajaxSettings, thrownError) {
        $('.content_area').html("<h2>Could not retrieve data</h2>");
        //alert('[event:' + event + '], [jqXHR:' + jqXHR + '], [ajaxSettings:' + ajaxSettings + '], [thrownError:' + thrownError + '])');
        });
    });

我发现您在数据对象中错误地将字符串与数组连接起来

$.ajax({
    type: "GET",
    url: '../ajax/ajax.php',
    data: 'ProdCatFil='+ProdCatFil+'&ProdSubCatFil='+ProdSubCatFil+'&BrandFil='+BrandFil,
    success: function(data) {
        $('.content_area').html(data);
    }       
}).error(function (event, jqXHR, ajaxSettings, thrownError) {
    $('.content_area').html("<h2>Could not retrieve data</h2>");
    //alert('[event:' + event + '], [jqXHR:' + jqXHR + '], [ajaxSettings:' + ajaxSettings + '], [thrownError:' + thrownError + '])');
});
$.ajax({
键入:“获取”,
url:“../ajax/ajax.php”,
数据:“ProdCatFil=”+ProdCatFil+”&prodspactfil=“+prodspactfil+”&BrandFil=”+BrandFil,
成功:功能(数据){
$('.content_area').html(数据);
}       
}).错误(函数(事件、jqXHR、ajaxSettings、thrownError){
$('.content_area').html(“无法检索数据”);
//警报('[event:'+event+']、[jqXHR:'+jqXHR+']、[ajaxSettings:'+ajaxSettings+']、[thrownError:'+thrownError+']);
});
尝试使用具有键/值对的对象可能会解决您的问题

$.ajax({
    type: "GET",
    url: '../ajax/ajax.php',
    data: { // Here I use an object with key/value pairs. If value is an Array, jQuery serializes multiple values with same key.
        'ProdCatFil': ProdCatFil,
        'ProdSubCatFil': ProdSubCatFil,
        'BrandFil': BrandFil
    },
    success: function(data) {
        $('.content_area').html(data);
    }       
}).error(function (event, jqXHR, ajaxSettings, thrownError) {
    $('.content_area').html("<h2>Could not retrieve data</h2>");
    //alert('[event:' + event + '], [jqXHR:' + jqXHR + '], [ajaxSettings:' + ajaxSettings + '], [thrownError:' + thrownError + '])');
});
$.ajax({
键入:“获取”,
url:“../ajax/ajax.php”,
数据:{//这里我使用一个具有键/值对的对象。如果值是数组,jQuery将使用同一个键序列化多个值。
“ProdCatFil”:ProdCatFil,
“ProdSubCatFil”:ProdSubCatFil,
“BrandFil”:BrandFil
},
成功:功能(数据){
$('.content_area').html(数据);
}       
}).错误(函数(事件、jqXHR、ajaxSettings、thrownError){
$('.content_area').html(“无法检索数据”);
//警报('[event:'+event+']、[jqXHR:'+jqXHR+']、[ajaxSettings:'+ajaxSettings+']、[thrownError:'+thrownError+']);
});
你能试试这个吗:

$('input[type="checkbox"]').change(function(){

    var name = $(this).attr("name");
    var ProdCatFil = [];
    var ProdSubCatFil = [];
    var BrandFil = [];

    // Loop through the checked checkboxes in the same group
    // and add their values to an array
    $('input[type="checkbox"]:checked').each(function(){

        switch(name) {

           case 'ProdCatFil[]': 
                ProdCatFil.push($(this).val());
                break;

           case 'ProdSubCatFil[]': 
                ProdSubCatFil.push($(this).val());
                break;

           case 'BrandFil[]': 
                BrandFil.push($(this).val());
                break;

           default:
                // Checkboxes which are not
                // a part of this loop.
                break;

        }

    });

    $("#loading").show();
    $('.content_area').hide();

    $.ajax({
        type: "GET",
        url: '../ajax/ajax.php',
        data: 'ProdCatFil=' + encodeURIComponent(ProdCatFil.join(",")) + '&ProdSubCatFil=' + encodeURIComponent(ProdSubCatFil.join(",")) + '&BrandFil=' + encodeURIComponent(BrandFil.join(",")),
        success: function(data) {
            $('.content_area').html(data);
        },
        complete: function () {
            $("#loading").hide();
            $('.content_area').show();
        }
    }).error(function (event, jqXHR, ajaxSettings, thrownError) {
        $('.content_area').html("<h2>Could not retrieve data</h2>");
        //alert('[event:' + event + '], [jqXHR:' + jqXHR + '], [ajaxSettings:' + ajaxSettings + '], [thrownError:' + thrownError + '])');
    });

});
$('input[type=“checkbox”]”)。更改(函数(){
var name=$(this.attr(“name”);
var ProdCatFil=[];
var prodspactfil=[];
var BrandFil=[];
//循环检查同一组中的复选框
//并将其值添加到数组中
$('input[type=“checkbox”]:checked')。每个(函数(){
交换机(名称){
案例“ProdCatFil[]”:
prodcafil.push($(this.val());
打破
案例“ProdSubCatFil[]”:
prodsubatfil.push($(this.val());
打破
案例“BrandFil[]”:
BrandFil.push($(this.val());
打破
违约:
//不可用的复选框
//这个循环的一部分。
打破
}
});
$(“#加载”).show();
$('.content_area').hide();
$.ajax({
键入:“获取”,
url:“../ajax/ajax.php”,
数据:“ProdCatFil=”+encodeURIComponent(ProdCatFil.join(“,”)+”&prodspactfil=”+encodeURIComponent(prodspactfil.join(“,”)+”&BrandFil=”+encodeURIComponent(BrandFil.join(“,”),
成功:功能(数据){
$('.content_area').html(数据);
},
完成:函数(){
$(“#加载”).hide();
$('.content_area')。
var detailGet = 'ProdCatFil='+ProdCatFil+'&ProdSubCatFil='+ProdSubCatFil+'&BrandFil='+BrandFil;
        // Use POST or GET
$.get("../ajax/ajax.php", detailGet, function (response, status, xhr) {
    if(status == "success") {
        $('.content_area').html(response);
    } else if(status == "error") {
        alert('Something when wrong.');                
    }
});
$.ajax({
    type: "GET",
    url: '../ajax/ajax.php',
    data: 'ProdCatFil='+ProdCatFil+'&ProdSubCatFil='+ProdSubCatFil+'&BrandFil='+BrandFil,
    success: function(data) {
        $('.content_area').html(data);
    }       
}).error(function (event, jqXHR, ajaxSettings, thrownError) {
    $('.content_area').html("<h2>Could not retrieve data</h2>");
    //alert('[event:' + event + '], [jqXHR:' + jqXHR + '], [ajaxSettings:' + ajaxSettings + '], [thrownError:' + thrownError + '])');
});
$.ajax({
    type: "GET",
    url: '../ajax/ajax.php',
    data: { // Here I use an object with key/value pairs. If value is an Array, jQuery serializes multiple values with same key.
        'ProdCatFil': ProdCatFil,
        'ProdSubCatFil': ProdSubCatFil,
        'BrandFil': BrandFil
    },
    success: function(data) {
        $('.content_area').html(data);
    }       
}).error(function (event, jqXHR, ajaxSettings, thrownError) {
    $('.content_area').html("<h2>Could not retrieve data</h2>");
    //alert('[event:' + event + '], [jqXHR:' + jqXHR + '], [ajaxSettings:' + ajaxSettings + '], [thrownError:' + thrownError + '])');
});
$('input[type="checkbox"]').change(function(){

    var name = $(this).attr("name");
    var ProdCatFil = [];
    var ProdSubCatFil = [];
    var BrandFil = [];

    // Loop through the checked checkboxes in the same group
    // and add their values to an array
    $('input[type="checkbox"]:checked').each(function(){

        switch(name) {

           case 'ProdCatFil[]': 
                ProdCatFil.push($(this).val());
                break;

           case 'ProdSubCatFil[]': 
                ProdSubCatFil.push($(this).val());
                break;

           case 'BrandFil[]': 
                BrandFil.push($(this).val());
                break;

           default:
                // Checkboxes which are not
                // a part of this loop.
                break;

        }

    });

    $("#loading").show();
    $('.content_area').hide();

    $.ajax({
        type: "GET",
        url: '../ajax/ajax.php',
        data: 'ProdCatFil=' + encodeURIComponent(ProdCatFil.join(",")) + '&ProdSubCatFil=' + encodeURIComponent(ProdSubCatFil.join(",")) + '&BrandFil=' + encodeURIComponent(BrandFil.join(",")),
        success: function(data) {
            $('.content_area').html(data);
        },
        complete: function () {
            $("#loading").hide();
            $('.content_area').show();
        }
    }).error(function (event, jqXHR, ajaxSettings, thrownError) {
        $('.content_area').html("<h2>Could not retrieve data</h2>");
        //alert('[event:' + event + '], [jqXHR:' + jqXHR + '], [ajaxSettings:' + ajaxSettings + '], [thrownError:' + thrownError + '])');
    });

});
<script type="text/javascript">
    $(document).ready(function () {
        $("input[type=checkbox]").change(function () {
            var name = $(this).attr("name");
            var ProdCatFil = [];
            var ProdSubCatFil = [];
            var BrandFil = [];
            // Loop through the checked checkboxes in the same group
            // and add their values to an array
            $('input[type=checkbox]:checked').each(function () {
                switch (name) {
                    case 'ProdCatFil[]':
                        ProdCatFil.push($(this).val());
                        break;

                    case 'ProdSubCatFil[]':
                        ProdSubCatFil.push($(this).val());
                        break;

                    case 'BrandFil[]':
                        BrandFil.push($(this).val());
                        break;
                }
            });

            $("#loading").ajaxStart(function () {
                $(this).show();
                $('.content_area').hide();
            });

            $("#loading").ajaxStop(function () {
                $(this).hide();
                $('.content_area').show();
            });

            $.ajax({
                type: "GET",
                url: 'ajaxReq.php',
                data: 'ProdCatFil=' + ProdCatFil + '&ProdSubCatFil=' + ProdSubCatFil + '&BrandFil=' + BrandFil,

                success: function (data) {

                    $('.content_area').html(data);
                }
            }).error(function (event, jqXHR, ajaxSettings, thrownError) {
                $('.content_area').html("<h2>Could not retrieve data</h2>");
                //alert('[event:' + event + '], [jqXHR:' + jqXHR + '], [ajaxSettings:' + ajaxSettings + '], [thrownError:' + thrownError + '])');
            });
        });
    });
</script>