表单提交中的Chrome iOS错误-重定向到错误的URL [英] Chrome iOS bug within form submit - redirects to wrong URL

查看:52
本文介绍了表单提交中的Chrome iOS错误-重定向到错误的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过jQuery更改表单的action属性.该功能适用​​于所有主流浏览器和设备,但不适用于chrome 72.0.3626.101 iOS.

I am changing the action attribute of a form via jQuery. This works on all major browser and devices BUT not on chrome 72.0.3626.101 iOS.

<form id="filter_form" action="/previous-folder/">
    <select name="brand" id="filter_brand">
        <option value="example">Example</option>
        <option value="test">Test</option>
    </select>
    <input id="filter_submit" type="submit" value="Suchen">
</form>

jquery代码:

<script>
    $("#filter_submit").on("click", function(e){
       $("#filter_form").attr("action", "/"+$("#filter_brand").val()+"/").submit();
       return false;
    });
</script>

因此,选择按钮确定URL,并应转到/example/?para ..

So the select button determines the URL and should go to /example/?para..

取而代之的是/previous-folder/#/example/?para

更改的URL是正确的,我尝试输出到控制台,这没问题.但是,iOS上提交的URL是其中提到的一个.在所有其他设备上均可使用.

The changing URL is correct, I tried outputing to console and it is OK. However the submited URL on iOS is the one mentioned. Works on all other devices.

URL受apache重写规则的影响:

The URL is by the way affected by an apache rewrite rule:

RewriteRule  ^/home/www/(example/(.*))/(ref-.*)?$ /subapp_search/index.php?fa=1&rw=1 [L]

如何调试和修复这种行为?

How to debug and fix such a behaviour?

推荐答案

我不建议在提交按钮单击事件中包含任何脚本.请改用表单提交事件

I do not recommend to have any script in a submit button click event. Use the form submit event instead

$("#filter_form").on("submit", function(e) {
  this.action =  "/" + $("#filter_brand").val() + "/"
});

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="filter_form" action="/previous-folder/">
  <select name="brand" id="filter_brand">
    <option value="example">Example</option>
    <option value="test">Test</option>
  </select>
  <input id="filter_submit" type="submit" value="Suchen">
</form>

这篇关于表单提交中的Chrome iOS错误-重定向到错误的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆