Получить параметры
Добрый день!
Помоги сделать, 2-ой день не могу сделать. Есть ячейки таблицы с уникальными классами (которые начинаются reload_, а после уникальное значение), при нажатии на который, название класса, без reload_, должно передаться в параметр sort вот ячейки <th scope="col" class="reload_id" style="cursor:pointer" onClick="document.location='index.php?sort=id&por=<?php echo $table_sort ?>'">id</th> <th scope="col" class="reload_name" style="cursor:pointer" onClick="document.location='index.php?sort=name&por=<?php echo $table_sort ?>'">Имя</th> <th scope="col" class="reload_price" style="cursor:pointer" onClick="document.location='index.php?sort=price&por=<?php echo $table_sort ?>'">Цена</th> $(document).ready(function(){ $('.reload_rating').click(function(){ $.ajax({ url: "index.php?sort=rating&por=<?php echo $table_sort ?>", cache: false, success: function(html){ $("#reloader").html(html); } }); }); }); и как потом передать в урл эти параметры |
Получить так - this.className.substr(7), а вставлять куда?
|
<th scope="col" class="filter-control reload_id" style="cursor:pointer">id</th> <th scope="col" class="filter-control reload_name" style="cursor:pointer">Имя</th> <th scope="col" class="filter-control reload_price" style="cursor:pointer">Цена</th> <script> $(document).ready(function() { var get_por = '<?php echo $table_sort ?>'; $('.filter-control').click(function() { location.href = 'index.php?sort =' + [].filter.call(this.classList, function(item) { return item.indexOf('reload_') == 0; }).shift().replace('reload_', '') + '&por=' + get_por; }); $('.reload_rating').click(function() { $.ajax({ url: "index.php?sort=rating&por=" + get_por, cache: false, success: function(html) { $("#reloader").html(html); } }); }); }); </script> |
огромное спасибо за помощь и прошу прощения, но я немного не так написал
вот все ячейки <th scope="col" class="reload_id filter-control" style="cursor:pointer">id</th> <th scope="col" class="reload_name filter-control" style="cursor:pointer">Имя</th> <th scope="col" class="reload_price filter-control" style="cursor:pointer"">Цена</th> <th scope="col" class="reload_rating filter-control" style="cursor:pointer">Рейтинг</th> $('.reload<сюда тоже подставить класс>').click(function() { $.ajax({ url: "index.php?sort=<и сюда тоже подставить класс>&por=" + get_por, cache: false, success: function(html) { $("#reloader").html(html); } }); }); если не тяжело, спасибо, потом буду разбирать))))) |
monah1983,
<th scope="col" class="reload_id filter-control">id</th> <th scope="col" class="reload_name filter-control">Имя</th> <th scope="col" class="reload_price filter-control">Цена</th> <th scope="col " class="reload_rating filter-control">Рейтинг</th> <style>.filter-control{cursor:pointer}</style> <script> $(document).ready(function() { var get_por = '<?php echo $table_sort ?>'; $('.filter-control').click(function() { var sort_by = [].filter.call(this.classList, function(item) { return item.indexOf('reload_') == 0; }).shift().replace('reload_', ''); $.ajax({ url: "index.php?sort=" + sort_by + " &por=" + get_por, cache: false, success: function(html) { $(" #reloader ").html(html); } }); }); }); </script> |
<style>.filter-control{cursor:pointer}</style> <script> $(document).ready(function() { var get_por = '<?php echo $table_sort ?>'; $('.filter-control').click(function() { var sort_by = [].filter.call(this.classList, function(item) { return item.indexOf('reload_') == 0; }).shift().replace('reload_', ''); $.ajax({ url: "index.php?sort=" + sort_by + " &por=" + get_por, cache: false, success: function(html) { $(" #reloader ").html(html); window.location.href = "index.php?sort=" + sort_by + "&por=" + get_por; } }); }); }); </script> код отлично работает, обновляет, берёт параметры, передает урл, но почему то обновляет страницу, но он по сути должен обновить таблицу без перезагрузки и в ставить в урл. что не так? |
Цитата:
|
удалил, но тогда в урл не передаются параметры
|
monah1983, для изменения url подойдет History API
var url = "index.php?sort=" + sort_by + "&por=" + get_por; $.ajax({ url: url, cache: false, success: function(html) { $(" #reloader ").html(html); !!window.history && history.replaceState({}, document.title, url); } }); ps. в адресе перед амперсандом пробела быть не должно. |
Часовой пояс GMT +3, время: 21:25. |