Firefox在jquery AJAX发布后在URL中显示表单数据 [英] Firefox displaying form data in URL upon jquery AJAX post

查看:56
本文介绍了Firefox在jquery AJAX发布后在URL中显示表单数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个登录表单,该表单调用jquery ajax请求并通过ASP.NET Web API端点发布表单数据.

I have a login form which calls a jquery ajax request and posts the form data via an ASP.NET Web API endpoint.

因此,该过程仅检查用户名和密码,如果匹配,则重定向到主页.当我从Chrome运行但在FireFox中进行测试时,它可以正常工作,但它没有重定向,但最糟糕的是,它会将表单数据放入URL中?为什么这样做?

So the process just checks username and password, and if it matches, redirect to home page. It works properly when I run from Chrome but I tested in FireFox and it's not redirecting but worst of all, it's putting the form data in the URL? Why is it doing that?

发布后,URL如下所示:

After posting, this is what the URL looks like:

http://localhost:50367/Account/Login?companycode=a&username=a&password=a

在Chrome中不会发生这种情况,而且我认为代码中没有任何会导致这种情况的原因.

This does not happen in Chrome and I don't think I have anything in my code that would cause this.

ajax调用看起来像这样:

The ajax call looks like this:

$.ajax({
    url: "/Account/Login",
    method: "POST",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    data: JSON.stringify(loginData)
})
.done((response) => {
    if (response.success) {
        window.location.href = response.returnUrl;
    }
})
.fail((error) => {      
});

是什么原因导致表单数据显示在Firefox的URL中?

What could be causing the form data to display in the URL for Firefox?

推荐答案

防止< form> 提交的默认操作.

form.onsubmit = function(event) {
  event.preventDefault();
  // do `$.ajax()` stuff
}

这篇关于Firefox在jquery AJAX发布后在URL中显示表单数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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