У меня есть файл jquery, в котором у меня есть 1 запрос на получение и 2 отправки запроса на сервер.
Я фильтрую некоторые данные в другой функции, которая является функцией пользовательского интерфейса. Проблема в том, что вызовы ajax некажется, что работает, то есть вызовы веб-службы не запускаются.
Элемент управления, похоже, не подходит ни к функции успеха, ни к ошибкам, где у меня мало предупреждений для удобства.
ИИсходный код этого js-файла, похоже, не отображается на вкладке источников в отладчике при попытке отладки того же самого.
Я использую весеннюю загрузку, Spring-Security и отдых веб-службы на сервересторона для того же.Любые указатели были бы хороши
$(document).ready(function() {
var deviceType;
var vehicleType;
var vehicleNumber;
var location;
var postion;
var distinguishedName;
var releaseVersion;
var actualData;
var filters = {
deviceType: [],
vehicleType: [],
vehicleNumber: [],
location: [],
postion: [],
distinguishedName: [],
releaseVersion: [],
};
$("#deviceType").change(function (event) {
filters.deviceType = [];
var ids = $(event.currentTarget).val();
$.each(ids, function (i, id) {
filters.deviceType.push(id);
});
filterData(actualData, filters);
});
$("#vehicleType").change(function (event) {
filters.vehicleType = [];
var ids = $(event.currentTarget).val();
$.each(ids, function (i, id) {
filters.vehicleType.push(id);
});
filterData(actualData, filters);
});
$("#vehicleNumber").change(function (event) {
filters.vehicleNumber = [];
var ids = $(event.currentTarget).val();
$.each(ids, function (i, id) {
filters.vehicleNumber.push(id);
});
filterData(actualData, filters);
});
$("#location").change(function (event) {
filters.location = [];
var ids = $(event.currentTarget).val();
$.each(ids, function (i, id) {
filters.location.push(id);
});
filterData(actualData, filters);
});
$("#postion").change(function (event) {
filters.postion = [];
var ids = $(event.currentTarget).val();
$.each(ids, function (i, id) {
filters.postion.push(id);
});
filterData(actualData, filters);
});
$("#distinguishedName").change(function (event) {
filters.distinguishedName = [];
var ids = $(event.currentTarget).val();
$.each(ids, function (i, id) {
filters.distinguishedName.push(id);
});
filterData(actualData, filters);
});
$("#releaseVersion").change(function (event) {
filters.releaseVersion = [];
var ids = $(event.currentTarget).val();
$.each(ids, function (i, id) {
filters.releaseVersion.push(id);
});
filterData(actualData, filters);
});
function applyIndividualFilter(items, filters, filterItem) {
if(filters[filterItem].length > 0) {
var newFilteredResult = [];
$.each(items, function (i, mpDetails) {
if(filters[filterItem].indexOf(mpDetails[filterItem]) > -1) {
newFilteredResult.push(mpDetails);
}
});
return newFilteredResult;
} else {
return items
}
}
function filterData(result, filters) {
var filteredResult = [];
var newFilteredResult = [];
if(filters) {
filteredResult = applyIndividualFilter(result, filters, 'deviceType');
filteredResult = applyIndividualFilter(filteredResult, filters, 'vehicleType');
filteredResult = applyIndividualFilter(filteredResult, filters, 'vehicleNumber');
filteredResult = applyIndividualFilter(filteredResult, filters, 'location');
filteredResult = applyIndividualFilter(filteredResult, filters, 'postion');
filteredResult = applyIndividualFilter(filteredResult, filters, 'distinguishedName');
filteredResult = applyIndividualFilter(filteredResult, filters, 'releaseVersion');
$("#select-all").hide();
} else {
filteredResult = result;
}
$("#customerTable tbody").empty();
$.each(filteredResult, function(i, mpDetails){
deviceType = mpDetails.deviceType;
vehicleType = mpDetails.vehicleType;
vehicleNumber = mpDetails.vehicleNumber;
location = mpDetails.location;
postion = mpDetails.postion;
distinguishedName = mpDetails.distinguishedName;
releaseVersion = mpDetails.releaseVersion;
var customerRow = "<tr><td><input type='checkbox' name='record'></td><td>" +
deviceType + "</td><td>" +
vehicleType + "</td><td>" +
vehicleNumber + "</td><td>" +
location + "</td><td>" +
postion + "</td><td>" +
distinguishedName + "</td><td>" +
releaseVersion + "</td></tr>";
$(customerRow).appendTo("#customerTable tbody");
});
}
// DO GET
$.ajax({
type : "GET",
url : "/populateVehicleData",
success: function(result){
actualData = result;
filterData(result, null);
$.each(result, function(i, mpDetails){
$("<option value='" + mpDetails.deviceType + "'>"+mpDetails.deviceType+"</option>").appendTo('#deviceType');
$("<option value='" + mpDetails.vehicleType + "'>"+mpDetails.vehicleType+"</option>").appendTo('#vehicleType');
$("<option value='" + mpDetails.vehicleNumber + "'>"+mpDetails.vehicleNumber+"</option>").appendTo('#vehicleNumber');
$("<option value='" + mpDetails.location + "'>"+mpDetails.location+"</option>").appendTo('#location');
$("<option value='" + mpDetails.postion + "'>"+mpDetails.postion+"</option>").appendTo('#postion');
$("<option value='" + mpDetails.distinguishedName + "'>"+mpDetails.distinguishedName+"</option>").appendTo('#distinguishedName');
$("<option value='" + mpDetails.releaseVersion + "'>"+mpDetails.releaseVersion+"</option>").appendTo('#releaseVersion');
});
var map = {};
$('select option').each(function () {
if (map[this.value]) {
$(this).remove()
}
map[this.value] = true;
});
},
error : function(e) {
alert("ERROR: ", e);
console.log("ERROR: ", e);
}
});
$('#select-all').click(function(event) {
if(this.checked) {
$(':checkbox').each(function() {
this.checked = true;
});
} else {
$(':checkbox').each(function() {
this.checked = false;
});
}
});
$('#reboot').click(function () {
var sendInfo = [];
$('#customerTable').find('tr').each(function (i) {
var row = $(this);
if (row.find('input[type="checkbox"]').is(':checked')) {
var $tds = $(this).find('td');
if($tds.text().length === 0) {
return true;
}
var domain = {
"deviceType": $tds.eq(1).text(),
"vehicleType": $tds.eq(2).text(),
"vehicleNumber": $tds.eq(3).text(),
"location": $tds.eq(4).text(),
"postion": $tds.eq(5).text(),
"distinguishedName": $tds.eq(6).text(),
"releaseVersion": $tds.eq(7).text(),
};
sendInfo.push(domain);
}
});
if( Array.isArray(sendInfo) && sendInfo.length === 0) { alert("Please select a vehicle"); return; }
$.ajax({
type: 'post',
url: '/rebootMp',
data: JSON.stringify(sendInfo),
contentType: "application/json; charset=utf-8",
traditional: true,
success: function(result){
alert("Reboot: "+result);
},
error : function(e) {
console.log("Error: ", e);
}
});
});
$('#logs').click(function () {
var sendInfo = [];
$('#customerTable').find('tr').each(function (i) {
var row = $(this);
if (row.find('input[type="checkbox"]').is(':checked')) {
var $tds = $(this).find('td');
if($tds.text().length === 0) {
return true;
}
var domain = {
"deviceType": $tds.eq(1).text(),
"vehicleType": $tds.eq(2).text(),
"vehicleNumber": $tds.eq(3).text(),
"location": $tds.eq(4).text(),
"postion": $tds.eq(5).text(),
"distinguishedName": $tds.eq(6).text(),
"releaseVersion": $tds.eq(7).text(),
};
sendInfo.push(domain);
}
});
if( Array.isArray(sendInfo) && sendInfo.length === 0) { alert("Please select a vehicle"); return; }
$.ajax({
type: 'post',
url: '/getAllLogsFromMp',
data: JSON.stringify(sendInfo),
contentType: "application/json; charset=utf-8",
traditional: true,
success: function(result){
alert("Get All Logs: "+result);
},
error : function(e) {
console.log("Error: ", e);
}
});
});
$("#filter_logo").click(function () {
if($(('#deviceType') && ('#vehicleType') && ('#vehicleNumber') && ('#location')
&& ('#postion') && ('#distinguishedName') && ('#releaseVersion')).is(":visible")){
hideElements();
} else{
showElements();
}
});
function hideElements(){
$('#deviceType').hide();
$('#vehicleType').hide();
$('#vehicleNumber').hide();
$('#location').hide();
$('#postion').hide();
$('#distinguishedName').hide();
$('#releaseVersion').hide();
}
function showElements(){
$('#deviceType').show();
$('#vehicleType').show();
$('#vehicleNumber').show();
$('#location').show();
$('#postion').show();
$('#distinguishedName').show();
$('#releaseVersion').show();
}
})