我已经复制了在本地主机上运行的简单Django forms example。当您点击提交按钮时,基本的联系表单示例应该提交POST请求。Chrome不在本地主机上发送POST请求,Firefox正常工作
我在Mac Snow Leopard上运行Chrome,每当我提交表单时,页面都会用一个空的表单重新加载:我可以从runserver输出中看到它没有发送POST - 而是发送GET请求。
如果我在Mac Snow Leopard的Firefox中打开相同的页面,并提交表单,我可以看到它发送POST请求(应该是这样)。
在Chrome浏览器中查看源代码时,表单肯定会显示method="post"
。
<form action="/contact/" method="post">
<p><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></p>
<p><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></p>
<p><label for="id_sender">Sender:</label> <input type="text" name="sender" id="id_sender" /></p>
<p><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></p>
<input type="submit" value="Submit" />
</form>
使用POST表单的外部网站在Chrome中似乎工作正常。此外,如果我填写的表单不正确,Chrome浏览器会像以前一样使用GET请求重新加载页面;在Firefox中,表单得到验证,因为它应该。
我试过用本地主机上的其他POST表单,并得到了相同的结果。
我知道Chrome for Mac有它的怪癖,但究竟是怎么回事?
谢谢。虽然:(i)我在表单上遇到了不涉及文件上传的问题,(ii)表单在Chrome中一直适用于locahost,这似乎是一件新事物。我只是想解决如何从Mac OS的命令行启动Chrome ......感叹 – AP257
我的评论与文件上传无关。如果您是通过'file://'URI访问网页,而不是通过'http://'URI访问网页,则每个文件都被视为自己的域。之前你不会看到这个的原因是,这种行为仅在2月24日的开发者频道更新中启用。 – jamessan
哦,我明白了。不,我使用的是http:// localhost:8080。现在这种行为已经消失了。离奇!不管怎么说,还是要谢谢你。 – AP257