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

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
2 anni 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";
}
2 anni 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
2 anni 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.
2 anni 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";
}
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.