Unable to call ajax method from Login page in NopCommerce 4.4.

10 mesi tempo fa
Login.cshtml code

$('#Email').blur(function () {
  if ($(this) == null) {
  }
  else {
    $.ajax({
      url: "@Url.Action("GetMobileNo")",
      type: 'post',
      success: function (data) {
        console.log(data);
      },
      error: function (xhr) {
        console.log(xhr.status.toString());
      },
    });
  }
});
--------------------------------------------------------------------------------
CustomerController.cs code
public string GetMobileNo()
{
   return "123456789";
}
10 mesi tempo fa
bhisepreeti wrote:
Login.cshtml code

$('#Email').blur(function () {
  if ($(this) == null) {
  }
  else {
    $.ajax({
      url: "@Url.Action("GetMobileNo")",
      type: 'post', 'get'
      success: function (data) {
        console.log(data);
      },
      error: function (xhr) {
        console.log(xhr.status.toString());
      },
    });
  }
});
--------------------------------------------------------------------------------
CustomerController.cs code
[HttpPost]
public string GetMobileNo()
{
   return "123456789";
}


try with get method or add HttpPost annotation
10 mesi tempo fa
I have tried with both get and post method and even add HttpPost annotation, still it is not working.
I am getting 401 status code.
10 mesi tempo fa
I am now able to call the ajax method from login page by commenting
[AutoValidateAntiforgeryToken] in CustomerController.cs  and by adding attribute [CheckAccessPublicStore(true)] on controller method.

CustomerController.cs
------------------------------------------
//[AutoValidateAntiforgeryToken]
public partial class CustomerController : BasePublicController{
}

[CheckAccessPublicStore(true)]
public string GetMobileNo(){
   return "12345";
}