ajaxjavascript-POST方法&x27;u';值的开头无效

ajaxjavascript-POST方法&x27;u';值的开头无效,javascript,jquery,ajax,Javascript,Jquery,Ajax,我有一个html页面的登录功能,不断返回我的错误400以上。不管我输入什么 我的html代码: $(文档).ready(函数(){ $('#btnLogin')。单击(函数(){ $.ajax({ url:“/api/User/LoginAsync”, 方法:“POST”, contentType:'应用程序/json', 数据:{ 用户名:$('#txtUsername').val(), 密码:$('#txtPassword').val() }, 成功:功能(响应){ setItem(“ac

我有一个html页面的登录功能,不断返回我的错误400以上。不管我输入什么

我的html代码:

$(文档).ready(函数(){
$('#btnLogin')。单击(函数(){
$.ajax({
url:“/api/User/LoginAsync”,
方法:“POST”,
contentType:'应用程序/json',
数据:{
用户名:$('#txtUsername').val(),
密码:$('#txtPassword').val()
},
成功:功能(响应){
setItem(“accessToken”,响应);
window.location.href=“UserAccountPage.html”;
}
});
});
});




您正在使用XML参数定义AJAX调用,但您正在API测试仪中传递JSON格式

正确的AJAX调用必须是:

$(document).ready(function() {
  $('#btnLogin').click(function() {
    $.ajax({
      url: '/api/User/LoginAsync',
      method: 'POST',

      contentType: 'application/json',
      data: JSON.stringify({
        userName: $('#txtUsername').val(),
        password: $('#txtPassword').val()
      }),
      success: function(response) {
        localStorage.setItem("accessToken", response);
        window.location.href = "UserAccountPage.html";
      }
    });
  });
});

contentType只涉及AJAX调用结果(它需要在响应中使用JSON)

您正在使用XML参数定义AJAX调用,但是您正在API测试仪中传递JSON格式

正确的AJAX调用必须是:

$(document).ready(function() {
  $('#btnLogin').click(function() {
    $.ajax({
      url: '/api/User/LoginAsync',
      method: 'POST',

      contentType: 'application/json',
      data: JSON.stringify({
        userName: $('#txtUsername').val(),
        password: $('#txtPassword').val()
      }),
      success: function(response) {
        localStorage.setItem("accessToken", response);
        window.location.href = "UserAccountPage.html";
      }
    });
  });
});

contentType只涉及AJAX调用结果(它要求响应中包含JSON)

您能分享错误吗?站点不允许我编辑,所以这里是我的错误,这看起来像是服务器端错误。某些验证未通过。我将查看服务器端验证程序。您需要联系服务器端以了解此错误。他们只能告诉你它的实际原因。你能分享错误吗?网站不允许我编辑,所以这是我的错误。这看起来像是服务器端错误。某些验证未通过。我将查看服务器端验证程序。您需要联系服务器端以了解此错误。他们只能告诉你真正的原因。