Я хочу изменить вид одной страницы в зависимости от того, какой флажок установлен.
Также, когда один отмечен, другой становится непроверенным.
<input class="searchType" type="checkbox"></input>
<input class="searchType2" type="checkbox"></input>
Я пробовал что-то подобное, но я не знаю, как добавить другое решение (если установлен другой флажок)
$('.searchType').click(function() {
alert($(this).attr('id')); //-->this will alert id of checked checkbox.
if(this.checked){
$.ajax({
type: "GET",
url: 'projects/index',
data: $(this).attr('id'),
success: function(data) {
alert('it worked');
alert(data);
$('#container').html(data);
},
error: function() {
alert('it broke');
},
complete: function() {
alert('it completed');
}
});
}
});
$('.searchType2').click(function() {
alert($(this).attr('id')); //-->this will alert id of checked checkbox.
if(this.checked){
$.ajax({
type: "GET",
url: 'projects/categories',
data: $(this).attr('id'),
success: function(data) {
alert('it worked');
alert(data);
$('#container').html(data);
},
error: function() {
alert('it broke');
},
complete: function() {
alert('it completed');
}
});
}
});
Когда я пытаюсь подобный код, в консоли сервера я получаю первый флажок:
Rendering projects/index.html.erb
Completed 200 OK in 217ms (Views: 197.8ms | ActiveRecord: 7.0ms)
А если проверено другое
Rendering projects/categories.html.erb
Completed 200 OK in 217ms (Views: 197.8ms | ActiveRecord: 7.0ms)
Кажется, что это работает, но на самом деле не меняет маршрут, все остается прежним
Приветствия