У меня есть выходные поля флажка из запроса к базе данных. Когда пользователь щелкает поле, я хочу, чтобы значение выбора вводилось как параметр ha sh в URL. Я также хочу использовать этот параметр в вызове ajax, чтобы получить параметр, который я могу затем ввести в другом вызове load_data ajax, который фильтрует динамическую таблицу данных c.
У меня есть большинство это работает, но отмеченная jQuery функция будет принимать только идентификатор строки в качестве параметра, а не любые другие имена строк. Также alert
(который я только вставил для целей тестирования) показывает int(10)
, но я только хочу, чтобы он показывал 10
.
Помещение onchange
в функцию не работало, поэтому Я поместил его в отдельные поля ввода.
Это часть запроса mysqli
echo '<input class="category-clear-selection authors" type="checkbox" value=" '.$row["lastname"].' " id=" '.$row["lastname"].' " onchange="marked(' . $row['id'] . ')" >'
Это функция
function marked(param1) {
location.hash = (param1);
var filter = [];
$(param1).each(function() {
filter.push($(this));
var filterStr = JSON.stringify(filter);
$.ajax({
url: 'filters-file.php',
type: 'post',
data: {
filter: filterStr
},
success: function(response) {
alert(response);
var query = (response); //use the response as a query and send the query to the load_data function to search the books dynamic table
load_data(1, query);
}
});
});
}
Это код для ответ функции
<?php //this file is used for handling the php to jquery function on click
//Retrieve the string, which was sent via the POST parameter
$filter = $_POST['filter'];
//Decode the JSON string and convert it into a PHP associative array.
$decoded = json_decode($filter, true);
//var_dump the array so that we can view it's structure.
// var_dump($decoded);
// echo ($decoded);
console.log($decoded);
foreach ($decoded as $k=>$v)
{
var_dump($v[0]); // etc.
}
?>