首页 > 解决方案 > 我用 jquery 附加数据,但在 laravel 中没有对这些数据处理任何事件

问题描述

我使用 laravel 5.6

我使用波纹管事件并附加div.categoryAjaxId

此代码正在运行并附加我的代码。

//--------- 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>');
            });
        }});
});

现在我想得到categoryAjaxIdID 。有以下事件:

//----- 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');
        }
    });
});

但这个事件不起作用。并且不显示任何内容console.log

谢谢你的帮助

标签: jqueryajaxlaravel-5

解决方案


您是否已经尝试过点击?

//----- 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');
    }
});
});

推荐阅读