【问题标题】:below ajax is not executing, I don't understand why下面的ajax没有执行,我不明白为什么
【发布时间】:2022-01-05 07:47:31
【问题描述】:

我对 ajax 比较陌生,我正在尝试通过控制器中的响应正文检查移动电子邮件来验证电子邮件和移动设备,我无法发现我的错误,因为 ajax 语法对我来说是新的,任何人都可以帮助我正确方向?谢谢你

$('#email','#mobile').blur(function(){
    alert("in validation");
    var enteredEmail = $("#email").val();
    var enteredMobile = $("#mobile").val();
        $.ajax({
            url : window.location + "checkmobileemail",
            data : {email:enteredEmail , mobile:enteredMobile},
            success : function(result) {
            if (result == 'Duplicate') {
                $("#emailMsg","#mobileMsg").html("Email or Mobile already exists");
                $("#email","#mobile").focus();
                $("#addButton","#saveChanges").prop("disabled",true);
            } else {
                $("#emailMsg","#mobileMsg").html("");
                $().prop("disabled",false);
            }
        }
    });

控制器:

@RequestMapping(value="/checkmobileemail",method= RequestMethod.GET)
@ResponseBody
public String checkMobileEmail(HttpServletRequest req, Model model) {
    String mobile = req.getParameter("mobile");
    String email = req.getParameter("email");
    String id = req.getParameter("id");
    System.err.println("id "+ id + "mobile: "+ mobile + " , email: " + email);
    return service.findByEmailAndMobile(email,mobile);
}

服务方式:

@Override
public String findByEmailAndMobile(String email, String mobile) {
    Customer customer = repository.findByEmailAndMobile(email,mobile);
    return (customer == null)? "Unique" : "Duplicate";
}

【问题讨论】:

  • 你可以试试这个,url : 'window.location.href + "/" + "checkmobileemail"' 并设置 contentType : 'application/json' 也设置 'type : "POST"'跨度>
  • Type 实际上在控制器中设置为'GET',因此它可以比较从数据库中输入的电子邮件和移动设备并显示消息,我是否需要将此 ajax 放入验证功能?因为它在它下面
  • 你能发布你的控制器方法吗
  • 你可以看到。
  • 您是否将您的网址设置为 'window.location.href + "/" + "checkmobileemail"' ?

标签: ajax spring validation


【解决方案1】:

将此与类属性一起使用。多个 id 似乎不适用于您正在使用的版本。

例如:-

$(document).ready(function(){ $(".test").change(function(){ 您的代码和使用更改方法。不要使用模糊。 }); });

HTML=>

它会起作用的。谢谢!

【讨论】:

  • 还设置 url : 'window.location.href + "/" + "checkmobileemail"' 并设置 contentType : 'application/json' 还设置 'type : "POST"'
  • skype => akash.upadhyay66 联系我我会看到的
猜你喜欢
  • 2019-06-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-08
  • 2012-05-03
  • 1970-01-01
相关资源
最近更新 更多