IE表单动作网址问题 [英] IE form action URL issue

查看:139
本文介绍了IE表单动作网址问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我开始调整我们的产品到IE兼容性。现在我只在IE中面临一个奇怪的问题。



我的表单网址类似于 https://x.com/formurl/dynamicvalue



和我的表单元素是

< form action =method ='post'> ;
...
< / form>



一些值 dynamicvalue
$ b


  • 计划

  • li> plan2
  • 1234443

  • 544



除IE以外的其他浏览器将动作发送到 https://x.com/formurl/dynamicvalue



IE表单行动发送到 https://x.com/formurl



我不知道为什么会发生这种情况,我可以替换document.URL来发布表单以解决问题。不过,我想要什么原因让IE删除 dynamicvalue



我正在测试IE-9

请别人教我。

预先致谢。

解决方案

在使用动作属性时,我也发现了Internet Explorer 11中的这个错误> action 设置为空字符串。

 < form action =method =post>< / form> 

如果在javascript中读取form.action属性并且当前URL不包含尾部斜线,网址的最后部分将被删除。也就是说,如果位置 example.com/xxx/yyy form.action ==example.com/xxx,而如果位置 example.com/xxx/yyy/ form.action ==example.com/xxx/yyy/。然而,如果表单是通过点击提交按钮发布的,它会发布到正确的URL,即 example.com/xxx/ yyy example.com/xxx/yyy/



我克服了这个使用jQuery的 attr 函数检查HTML中的 action =,然后使用



$ p $ < =='')return location.href else return $(form).attr('action')

(为什么有人会这样做?我拦截表单提交并使用ajax发送数据。为此,我需要知道表单要提交的位置)


Recently i am started tuning our products to IE compatability. Now i am facing a weird problem in IE alone.

My form url is something like this https://x.com/formurl/dynamicvalue

and my form element is

<form action="" method='post'> ... </form>

some values the dynamicvalue holds are ( Alphanumeric characters )

  • plan
  • plan2
  • 1234443
  • 544

Except IE every other browsers sending the actions to https://x.com/formurl/dynamicvalue

IE form action is sending to https://x.com/formurl

I don't know why this is happening, I can replace the document.URL to post the Form back to solve the problem. Still, i want to what's the reason for IE to remove that dynamicvalue

I am testing in IE-9

Kindly someone teach me.

Thanks in advance.

解决方案

I have also discovered this bug in Internet Explorer 11 when reading the action attribute of a form with action set to the empty string.

<form action="" method="post"></form>

If one reads the form.action attribute in javascript and the current URL does not contain a trailing slash, the last part of the URL will be removed. I.e., if the location is example.com/xxx/yyy, form.action=="example.com/xxx, while if location is example.com/xxx/yyy/, form.action=="example.com/xxx/yyy/.

However, if the form is posted by clicking a submit button, it is posted to the correct URL, i.e., example.com/xxx/yyy or example.com/xxx/yyy/.

I overcame this by using jQuery's attr function to check if action="" in the HTML and then I use location.href instead.

if($(form).attr('action') === '') return location.href else return $(form).attr('action')

(Why would someone do this? I am intercepting the form submit and using ajax to send the data. To do this, I need to know where the form wants to submit)

这篇关于IE表单动作网址问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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