2

I use laravel 5.6

I use bellow event and append div.categoryAjaxId .

this code is working and append my code .

//--------- get product -------------------------
jQuery('.orderProduct').click(function(e){
    var productId = $(this).attr('id');
    var token = '{{ csrf_token() }}';

    e.preventDefault();

    jQuery.ajax({
        url: "{{ url('order/getCategoryAjax') }}",
        method: 'post',
        data: {
            id: productId,
            _token: token
        },
        success: function(data){
            $('#orderProductSelect').hide();
            $('.categoryAjax').show();
            $.each(data, function(index,category){
                $('.categoryAjax').append('<div class="col-md-4 categoryAjaxId" id="'+category.id+'" style="margin: 10px;cursor: pointer;">' +
                    '<img style="width: 100%;" src="/images/'+category.filename+'">' +
                    '<span>'+category.name+'</span>' +
                    '</div>');
            });
        }});
});

now I want get categoryAjaxId ID . with bellow event :

//----- get feature and value of category --------------------
jQuery('.categoryAjaxId').click(function(e){
    var categoryId = $(this).attr('id');
    console.log(categoryId);
    var token = '{{ csrf_token() }}';

    e.preventDefault();

    jQuery.ajax({
        url: "{{ url('order/getFeatureAjax') }}",
        method: 'post',
        data: {
            id: categoryId,
            _token: token
        },
        success: function(data) {
            $('.categoryAjaxId').hide();
            $('.featureAjax').show();
            $('.featureAjax').append('xxxxxxxxxxx');
        }
    });
});

but this event not working . and not show anything in console.log .

Thanks your help

1 Answers1

1

Have you tried on click already?

//----- get feature and value of category --------------------
jQuery('.categoryAjaxId').on('click',function(e){
var categoryId = $(this).attr('id');
    //console.log(categoryId);
var token = '{{ csrf_token() }}';

e.preventDefault();

jQuery.ajax({
    url: "{{ url('order/getFeatureAjax') }}",
    method: 'post',
    data: {
        id: categoryId,
        _token: token
    },
    success: function(data) {
        $('.categoryAjaxId').hide();
        $('.featureAjax').show();
        $('.featureAjax').append('xxxxxxxxxxx');
    }
});
});
Wimanicesir
  • 4,606
  • 2
  • 11
  • 30