简体   繁体   English

Firefox在jquery AJAX发布后在URL中显示表单数据

[英]Firefox displaying form data in URL upon jquery AJAX post

I have a login form which calls a jquery ajax request and posts the form data via an ASP.NET Web API endpoint. 我有一个登录表单,该表单调用jquery ajax请求并通过ASP.NET Web API端点发布表单数据。

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? 当我从Chrome运行但在FireFox中进行测试时,它可以正常工作,并且不重定向,但最糟糕的是,它会将表单数据放入URL中? Why is it doing that? 为什么这样做呢?

After posting, this is what the URL looks like: 发布后,URL如下所示:

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

This does not happen in Chrome and I don't think I have anything in my code that would cause this. 这种情况在Chrome中不会发生,并且我认为代码中没有任何会导致这种情况的原因。

The ajax call looks like this: ajax调用看起来像这样:

$.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) => {      
});

What could be causing the form data to display in the URL for Firefox? 是什么原因导致表单数据显示在Firefox的URL中?

Prevent the default action of <form> submission. 阻止<form>提交的默认操作。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM