JavaScript location.href不重定向

时间:2018-10-22 11:35:49

标签: javascript php jquery redirect

我的问题是location.href不能将我重定向到我想要的页面。它的作用是重新加载页面。

我尝试使用按钮,没有preventdefault(),但是仍然遇到相同的问题。

<script type="text/javascript">
    $(document).ready(function(e) 
    {
        $('#submitButton').click(function(e)
        {
            e.preventDefault();
            var iro = $('#iro').val();
            var date_start = $('#date_start').val();
            var date_end = $('#date_end').val();
            location.href = "https://site.hu/cms/uj-kifizetes.php?iro="+iro+"&date_start="+date_start+"&date_end="+date_end+"&lekerdezes=1";
        });
    });
</script>

<select name="iro" id="iro" class="input input-select">
    <?php
    $ertek = isset($_POST["iro"]) ? $_POST["iro"] : '' ;
    $get_irok = mysqli_query($kapcs, "SELECT iro_id, iro_nev FROM iro WHERE iro_status = 1 ORDER BY iro_nev ASC");
    if(mysqli_num_rows($get_irok) > 0 )
    {
        while($irok = mysqli_fetch_assoc($get_irok))
        {
            $selected = $ertek == $irok['iro_id'] ? ' selected="selected"':'';
            echo '<option ' . $selected . ' value="'.$irok['iro_id'].'">'.$irok['iro_nev'].'</option>';
        }
    } 
    ?>
</select>

<td style="text-align: center;">
<input autocomplete="off" class="datepicker" type="text" name="date_start" id="date_start" required value="<?php if(isset($_POST['date_start'])) { echo $_POST['date_start'];} ?>" />
</td>
<td style="text-align: center;">
<input autocomplete="off" class="datepicker" type="text" name="date_end" id="date_end" required value="<?php if(isset($_POST['date_end'])) { echo $_POST['date_end'];} ?>" />
</td>
<td style="text-align: center;"><button class="btn saveButton" name="submitButton" id="submitButton" type="submit">Lekérdezés</button></td>

2 个答案:

答案 0 :(得分:0)

尝试location.replace

location.replace('https://developer.mozilla.org/en-US/docs/Web/API/Location.reload');

答案 1 :(得分:-2)

更改此行

 <td style="text-align: center;"><button class="btn saveButton" name="submitButton" id="submitButton" type="submit">Lekérdezés</button></td>

对此

 <td style="text-align: center;"><input class="btn saveButton" name="submitButton" id="submitButton" type="button">Lekérdezés</button></td>

 $('#submitButton').click(function(e)
        {
            var iro = $('#iro').val();
            var date_start = $('#date_start').val();
            var date_end = $('#date_end').val();
            location.href = "https://site.hu/cms/uj-kifizetes.php?iro="+iro+"&date_start="+date_start+"&date_end="+date_end+"&lekerdezes=1";
        });

一切都会好起来的。