简体   繁体   English

如何向url添加搜索参数

[英]How to add search parameters to url

There is a form to filter and show tires.有一个表格可以过滤和显示轮胎。 It uses data from the databases: car model, car year and so on.它使用来自数据库的数据:汽车型号、汽车年份等。 The results are shown under the form.结果显示在表格下方。 What I want is to place the results in url to use it in filter.我想要的是将结果放在 url 中以在过滤器中使用它。

<form id="select_form" action="/" method="POST">

  <label>Производитель:</label>
  <select id="category1" name="vendor">
    <?php echo $opt->ShowCategory(podbor_shini_i_diski);  ?>
  </select>
  <label>Марка:</label>
  <select id="type1" name="car">
    <option value="0">Выбрать...</option>
  </select>

  <label>Год выпуска:</label>
  <select id="year1" name="year">
    <option value="0">Выбрать...</option>
  </select>

  <label>Модификация:</label>
  <select id="modification1" name="mod">
    <option value="0">Выбрать...</option>
  </select>

  <input id="sendForm" type="submit" class="button" value="Подтвердить" />
</form>
<div id="result"></div>

There is also a jquery还有一个jquery

jQuery(function($) {
  var table = "podbor_shini_i_diski";
  var show = "3";
  $("select#type1").attr("disabled", "disabled");
  $("select#year1").attr("disabled", "disabled");
  $("select#modification1").attr("disabled", "disabled");

  $("select#category1").change(function() {
    $("select#type1").attr("disabled", "disabled");
    $("select#type1").html("<option>Ждите...</option>");
    var vendor = $("select#category1 option:selected").attr('value');
    $.post("/auto-parts/select_type.php", {
      vendor: vendor,
      table: table
    }, function(data) {
      $("select#type1").removeAttr("disabled");
      $("select#type1").html(data);
    });
  });

  $("select#type1").change(function() {
    $("select#year1").attr("disabled", "disabled");
    $("select#year1").html("<option>Ждите...</option>");
    var vendor = $("select#category1 option:selected").attr('value');
    var car = $("select#type1 option:selected").attr('value');
    $.post("/auto-parts/select_year.php", {
      vendor: vendor,
      car: car,
      table: table
    }, function(data) {
      $("select#year1").removeAttr("disabled");
      $("select#year1").html(data);
    });
  });

  $("select#year1").change(function() {
    $("select#modification1").attr("disabled", "disabled");
    $("select#modification1").html("<option>Ждите...</option>");
    var vendor = $("select#category1 option:selected").attr('value');
    var car = $("select#type1 option:selected").attr('value');
    var year = $("select#year1 option:selected").attr('value');
    $.post("/auto-parts/show_modification.php", {
      vendor: vendor,
      car: car,
      year: year,
      table: table
    }, function(data) {
      $("select#modification1").removeAttr("disabled");
      $("select#modification1").html(data);
    });
  });

  $("form#select_form").submit(function() {
    var vendor = $("select#category1 option:selected").attr('value');
    var car = $("select#type1 option:selected").attr('value');
    var year = $("select#year1 option:selected").attr('value');
    var mod = $("select#modification1 option:selected").attr('value');
    $.post("/auto-parts/shini_show.php", {
        vendor: vendor,
        car: car,
        year: year,
        mod: mod,
        table: table,
        show: show
      },
      function(data) {
        $("#result").html(data);
      });
    return false;
  });
});

And the part of code和代码部分

if ($zavod_shini != "") {
  echo "<TR><TD><h3>Заводская комплектация</h3></TD></TR>\r\n";

  $zavod_shini_ = explode('|', $zavod_shini);

  for ($j = 0; $j <= count($zavod_shini_); $j++) {
    $zav_width_[$j] = substr($zavod_shini_[$j], 0, 3);
    $zav_height_[$j] = substr($zavod_shini_[$j], 4, 2);
    $zav_diam_[$j] = substr($zavod_shini_[$j], 8, 2);
    if ($zavod_shini_[$j] != "")
      echo "<TR><TD><a href='../?pa_shirina-profilya=$zav_width_[$j]&pa_vysota-profilya=$zav_height_[$j]&pa_diameter=$zav_diam_[$j]'>".$zavod_shini_[$j].
    "</a></TD></TR>\r\n";
  }
}

The problem is I don't know how to add the parameters from the result to url using ajax maybe问题是我不知道如何使用ajax将结果中的参数添加到url

Try like this像这样尝试

$.get("/auto-parts/shini_show.php?vendor=vendor&car=car&year=year&mod=mod&table=table&show=show",
  function(data) {
    $("#result").html(data);
  });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM