jQuery.post 表单仅在 Firefox 中提交奇怪的错误
我一直在寻找这个问题的答案,但不幸的是我被困住了。该问题仅出现在 Firefox 中(也测试了 IE、Chrome 和 Safari - 工作正常,没有任何类型的错误)。我将详细说明事件的顺序,以保存发布我的所有代码。
- ASP.NET MVC 3 应用程序,基本表单加载到 jQuery UI 对话框中
- 自定义 jQuery 来 hijax 表单提交(序列化表单,然后 $.post 到服务器 - 调试时没有编译器错误,并且 post 显示在 Firebug 中,没有错误)
- Http GET(自动发生)从服务器获取响应对象(+成功文本和 XHR),在这种情况下响应是纯 HTML(再次显示在 Firebug 中,没有错误)
- 自定义 jQuery 来更改 UI 对话框的 HTML当前的 HTML 到响应 Html - 这就是它失败的地方。
我使用 javascript 警报来调试事件序列,一旦发布(和获取)完成,一切就......有点停止。
正如我所说,仅在 Firefox 中! 非常奇怪,只是想知道 ajax 和 firefox 是否存在任何已知的错误,或者有人听说过类似的情况吗?
我还必须补充一点,在我网站的其他部分,这在所有浏览器中都能完美运行!此表单与其他成功完成该功能的表单之间的唯一区别在于,此表单的响应是再次但更新的相同“页面”,而不是新的“页面”。 (我使用“页面”,因为我首先关闭了 Javascript 并进行了优雅的降级,从而完成了所有这些工作)
帮助!或者笑,都可以。
更新
我尝试发送一个带有空白模型的视图作为操作结果 - 在除 Firefox 之外的所有浏览器中都有效 - Firefox 保留上一篇文章中的值!然后我开始思考——这就是 Firefox 的特点,不是吗?也许这就是为什么原来的“重定向”html 响应不起作用?我认为是时候放弃并让人们知道他们不能使用 Firefox 来实现该特定功能!
I've search high and low for an answer to this but unfortunately I'm stuck. The problem is only occuring in Firefox (tested IE, Chrome and Safari also - works fine, no errors of any sort). I'll detail the sequence of events to save posting all my code.
- ASP.NET MVC 3 application, basic form loads into a jQuery UI dialog
- Custom jQuery to hijax the form submit (serialize the form and then $.post to the server - no compiler errors when debugging and post shows up in Firebug without errors)
- Http GET (automatically happens) getting the response object from the server (+ success text and XHR), response is plain HTML in this case (again, shows up in Firebug with no errors)
- Custom jQuery to change the HTML of the UI dialog from it's current HTML to the response Html - this is where it fails.
I've used javascript alerts to debug the sequence of events and as soon as the post (and get) is complete, everything just... sort of stops.
As I say, only in firefox! Very odd, just wondering if there's any known bugs with ajax and firefox or anybody has heard of a similar situation?
I must also add, that on other parts of my site, this works perfectly in all browsers! The only difference between this form and the other forms that do successfully complete the function is that the response from this form is the same "page" again but updated rather than a new "page". (I use "page" as I got all this working with Javascript turned off first and for graceful degredation)
HELP! Or laugh, either is fine.
UPDATE
I have tried sending a view with a blank model back as the action result - works in every browser except firefox - firefox retains the values from the previous post! And then I got to thinking - that's a trait of firefox isn't it? And maybe that's why the original "re-direct" html response doesn't work?? I think it's time to give up and let people know they can't use Firefox for that particular function!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我正在回答我自己的问题。
我发现解决这个问题的唯一方法是使用
$.ajax
而不是$.post
并使用选项async : false
希望这对某人有帮助。
抢
Ok so I'm answering my own question.
The only way I found to get round it is to use
$.ajax
instead of$.post
and to use the optionasync : false
Hope this helps somebody.
Rob
您是否尝试过将属性
[OutputCache(Location = System.Web.UI.OutputCacheLocation.None)]
添加到您的 GET 操作中?在我看来,这像是一个缓存问题。Have you tried adding the attribute
[OutputCache(Location = System.Web.UI.OutputCacheLocation.None)]
to your Action for your GET? It sounds to me like a caching issue.