【发布时间】:2020-02-29 03:11:32
【问题描述】:
在我的函数中,我使用 jquery 搜索 owl carousel 的所有项目,并从 id 中仅获取可用的数字。因为我只需要物品的ID号。我通过 ajax 将 ID 号发送到我的 php 控制器以进行进一步处理。
var slideArray = $('#categoryInterestCarousel_' + categoryIdOld).find('.interestOwl');
//Step 1: initialize the array
var previewIds = [];
//Step 2: Search for all IDs and add only the id to the array
$(function() {
$(slideArray).each(function(index) {
previewIds[index] = $(this).attr('id').replace(/\D/g, '');
});
});
作为输出,我得到以下数组:
array:3 [
0 => "183"
1 => "198"
2 => "201"
]
我需要不带引号的数组,它看起来像:
array:3 [
0 => 183
1 => 198
2 => 201
]
通过ajax发送数据:
$.ajax({
type: 'GET',
url: '/categorie/owl/' + categoryIdOld,
data: {
previewIds: previewIds
},
success: function(data) {
//add some data to view
},
error: function(xhqr, staus, message) {
var response = JSON.parse(xhqr.responseText);
var errors = response.errors;
for (var error_key in errors) {
var error = errors[error_key];
_toastr_new(error, "top-full-width", "error", false, '.toastr-notify', 0);
}
}
});
在控制器上获取数据:
public function ajaxOwlItems(Request $request, $id) {
$preview_id = $request->previewIds;
dd($request->previewIds);
}
我的错误在哪里?如何去掉引号?
【问题讨论】:
-
您真正要问的是如何将字符串转换为数字,从而在网络搜索中显示大量结果
标签: php jquery arrays laravel replace