working with JSON data array from Ajax response?

后端 未结 5 1696
一个人的身影
一个人的身影 2020-12-21 21:26

Is it possible to work with a response from AJAX request in PHP? I am not really a JS dev so i am polling my hair out with this one.

I have sort of hacked this toget

5条回答
  •  没有蜡笔的小新
    2020-12-21 21:38

    $('input[name=\'product_attribute[' + attribute_row + '][name]\']').catcomplete({
        delay: 0,
        source: function(request, response) {
            $.ajax({
                url: 'index.php?route=catalog/attribute/autocomplete&token=',
                type: 'POST',
                dataType: 'json',
                data: 'filter_name=' +  encodeURIComponent(request.term),
                success: function(data) {   
                    response($.map(data, function(item) {
                        return {
                            category: item.attribute_group,
                            label: item.name,
                            value: item.attribute_id
                        }
                    }));
                }
            });
        }, 
        select: function(event, ui) {
            $('input[name=\'product_attribute[' + attribute_row + '][name]\']').attr('value', ui.item.label);
            $('input[name=\'product_attribute[' + attribute_row + '][attribute_id]\']').attr('value', ui.item.value);
    
            return false;
        }
    });
    

    You Can map your json something like this

提交回复
热议问题