2

Below is my Ajax request. When something is changed in the form standard_filter, such as a checkbox being clicked, the function is triggered. It all seems to work fine, the data is even passed on as can be seen in the image. After done() however, the data just seems to be empty? I can't figure out why, when I log the result it is simply [object object], any idea what the problem could be?

$('.standard_filter').on('change', function(e) {
        var form = $('.standard_filter');
        var inputId = e.target.getAttribute('id');
        var inputName = e.target.getAttribute('name');
        var inputValue = e.target.getAttribute('value');
        var inputLabel = $(e.target).next("label").text();
        alert(inputName);
        $.ajax({
            url : form.attr('action'),
            method : form.attr('method'),
            dataType : 'jsonp';
            data : {
                id : inputId,
                name : inputName,
                value : inputValue,
                label : inputLabel
            },
        }).done(function(data){
            //do the filter
            // show the filters
            $('.ctlg_active_filters').addClass('active');
            alert(data);
        });
    });

below are screenshots of the resonse:

enter image description here enter image description here

felixo
  • 1,453
  • 6
  • 33
  • 60
  • 5
    `[object Object]` is what *any* object looks like when forced to be a string value, as the `alert()` function will do. Try `console.dir(data)` instead. – Pointy Sep 06 '19 at 13:10
  • mhm okay I was not aware of that! but `console.dir(data)` returns the same '[object Object]' – felixo Sep 06 '19 at 13:12
  • Your browser has a "Network" developer tool that will show you the actual contents of the HTTP response. – Pointy Sep 06 '19 at 13:16
  • @Pointy alright so I managed to get the data with the help of a callback function, but its not quite what I expected. I expect he `id`, `name`, `value` and `label`of that specific target, but for some reason I am returned an object of the whole `standard_filter` `form`. I am so confused. – felixo Sep 06 '19 at 13:43

0 Answers0