jquery - 我用 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>');
});
}});
});
现在我想得到categoryAjaxId
ID 。有以下事件:
//----- 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
。
谢谢你的帮助
解决方案
您是否已经尝试过点击?
//----- 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');
}
});
});
推荐阅读
- html - 如何使用 sed 将 CSS 样式文件内联到 HTML 文件?
- r - 从后验预测分布抽样(stan vs inla)
- html - 反应渲染问题
- flutter - 如何在flutter中包含要由您自己的包使用的文件资产
- installation - 未找到 CMake 错误变量 LIBXML2_INCLUDE_DIR (Gate-9.0)
- javascript - 检查 div 是否有类然后动画
- typo3 - 在 fe_users 中自动填写字段名称
- objective-c - “AXUIElementCopyAttributeValues”返回“kAXErrorAPIDisabled”
- php - 排队的 Laravel 通知卡在 AWS SQS 上
- c - 如果在已分配的内存上使用 strdup 会发生什么